19 package org.turro.mail.pool;
21 import java.net.MalformedURLException;
22 import java.util.function.Consumer;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.mail.internet.InternetAddress;
26 import javax.naming.NamingException;
27 import org.apache.commons.mail.EmailException;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.mail.message.MailMessage;
38 private final Consumer onFinish;
42 this.onFinish = onFinish;
46 if(mail ==
null)
return;
49 Logger.getLogger(
MailQueueItem.class.getName()).log(Level.INFO,
"Sent mail from {0} to {1}. Subject: {2}",
50 new Object[]{mail.getEmail().getFromAddress().getAddress(),
51 InternetAddress.toString((InternetAddress[]) mail.getEmail().getToAddresses()
52 .toArray(new InternetAddress[0])), mail.getSubject()});
53 }
catch (MalformedURLException | NamingException | EmailException ex) {
56 if(onFinish !=
null) {
58 onFinish.accept(mail);
59 }
catch (Exception ex) {
static String logMsg(String msg)
MailQueueItem(MailMessage mail, Consumer onFinish)