package info.bukova.isspst.mail;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;

public class SimpleMailer implements Mailer {
	
	private JavaMailSender sender;
	private String from;
	
	public SimpleMailer(JavaMailSender sender) {
		this.sender = sender;
	}

	@Override
	@Async
	public void send(MailMessage message) {
		if (message.getFrom() == null || message.getFrom().isEmpty()) {
			if (from == null || from.isEmpty()) {
				message.setFrom("tomcat@is.bukova.info");
			} else {
				message.setFrom(from);
			}
		}
		
		sender.send(message);
	}

	public void setFrom(String from) {
		this.from = from;
	}

}
