All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lwapp.notification.email.Email Maven / Gradle / Ivy

Go to download

Lwapp notification is a utility jar file with most common notification features(email, sms, twitter) needed in daily java programming.

The newest version!
package org.lwapp.notification.email;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.Validate;

@XmlRootElement(name = "Email")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Email", propOrder = { "toAddresses", "subject", "messageBody", "attachments" })
public class Email implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@XmlElementWrapper(name = "toAddresses")
	@XmlElement(name = "toAddress")
	private final List toAddresses = new ArrayList<>();
	private final String subject;
	private final String messageBody;
	@XmlElementWrapper(name = "attachments")
	@XmlElement(name = "attachment")
	private final List attachments = new ArrayList<>();

	@SuppressWarnings("unused")
	private Email() {
		subject = null;
		messageBody = null;
	}

	public Email(final String subject, final String messageBody, final String... toAddresses) {
		Validate.notBlank(subject, "Missing subject for email.");
		Validate.notBlank(messageBody, "Missing email message body.");
		Validate.notEmpty(toAddresses, "Missing email addresses.");
		this.toAddresses.addAll(Arrays.asList(toAddresses));
		this.subject = subject;
		this.messageBody = messageBody;
	}

	public Email(final List toAddresses, final String subject, final String messageBody, final EmailAttachment... attachments) {
		Validate.notBlank(subject, "Missing subject for email.");
		Validate.notBlank(messageBody, "Missing email message body.");
		Validate.notNull(toAddresses, "Missing email addresses.");
		Validate.notEmpty(toAddresses.toArray(), "Missing email addresses.");
		Validate.notEmpty(attachments, "Missing email attachment.");

		this.toAddresses.addAll(toAddresses);
		this.subject = subject;
		this.messageBody = messageBody;
		this.attachments.addAll(Arrays.asList(attachments));
	}

	public List getToAddresses() {
		return toAddresses;
	}

	public String getSubject() {
		return subject;
	}

	public String getMessageBody() {
		return messageBody;
	}

	public List getAttachments() {
		return attachments;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy