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

br.com.jhonsapp.email.dispatcher.EmailDispatcherImpl Maven / Gradle / Ivy

Go to download

Email Dispatcher is an open source project created by Jhonys Camacho and Jhonathan Camacho to facilitate the sending of emails.

There is a newer version: 1.0.3
Show newest version
package br.com.jhonsapp.email.dispatcher;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.outjected.email.api.MailMessage;
import com.outjected.email.api.SendFailedException;

/**
 * Class responsible for dispatcher the emails.
 * 
 * @author Jhonathan Camacho
 *
 */
@Service
public class EmailDispatcherImpl implements EmailDispatcher {

	/**
	 * Generated serial version id created at 08 July 2017.
	 */
	private static final long serialVersionUID = -4126868513984414914L;

	private MailMessage mailMessage;

	@Autowired
	public EmailDispatcherImpl(MailMessage mailMessage) {
		this.mailMessage = mailMessage;
	}

	@Override
	public boolean send(Message message) {

		if (message == null)
			throw new IllegalArgumentException("The message can not be null.");

		try {

			mailMessage.to(message.getSender())
						.subject(message.getSubject())
						.bodyHtml(message.getHtmlContent())
						.send();
			
			return true;
			
		} catch (SendFailedException e) {
			return false;
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy