19 package org.turro.mail.pool;
21 import java.util.Date;
22 import java.util.HashSet;
25 import java.util.function.Consumer;
26 import javax.mail.internet.InternetAddress;
27 import org.apache.commons.mail.EmailException;
28 import org.turro.elephant.context.IConstructor;
29 import org.turro.log.WebLoggers;
30 import org.turro.mail.message.MailMessage;
31 import org.turro.mail.message.MailMessageTemplate;
32 import org.turro.mail.provider.MailProvider;
33 import org.turro.marker.ElephantMarker;
41 private final Date date =
new Date();
42 private final Set<MailMessage> pool =
new HashSet<>();
45 String message, String
template, String name, String login) {
46 return addToPoolTemplate(from, to, cc, subject, message,
template, name, login,
null);
50 String message, String
template, String name, String login, Map args) {
63 em.
put(
"body", message);
69 }
catch (EmailException ex) {
88 }
catch (EmailException ex) {
96 mail.
addHeader(
"X-Mailer",
"Elephant Mail System");
97 mail.setSentDate(date);
98 mail.setSubject(cleanSubject(mail.getSubject()));
103 mail.getProvider().getFrom().getMail(),
104 InternetAddress.toString((InternetAddress[]) mail.getEmail().getToAddresses().toArray(
new InternetAddress[0])),
109 }
catch(Exception ex) {
128 private String cleanSubject(String subject) {
129 subject = subject.replaceAll(
"\\<\\/?[\\?a-zA-Z\\-\\:\\_0-9]+\\ ?.*?\\>",
"");
130 subject = subject.replaceAll(
"\\n|\\r",
" ");
136 private final IConstructor constructor;
137 private final MailProvider provider;
144 this.constructor = constructor;
145 this.provider = provider;
WebLoggers message(String text, Object... parameters)
static WebLoggers severe(Object entity)
WebLoggers exception(Throwable throwable)
static WebLoggers info(Object entity)
void setMessage(ElephantMarker marker, IContact contact)
static MailMessageTemplate of(MailProvider provider)
Email addCc(String email, String name)
Email addTo(String email, String name)
void setMessage(String message)
static MailMessage of(MailProvider provider)
void setSubject(String subject)
void addHeader(String name, String value)
void sendPool(Consumer onFinish)
MailMessagePool(IConstructor constructor, MailProvider provider)
static MailMessagePool of(IConstructor constructor, MailProvider provider)
MailMessage addToPoolTemplate(String from, String to, String cc, String subject, String message, String template, String name, String login, Map args)
MailMessage addToPool(MailMessage mail)
MailMessage addToPool(String from, String to, String cc, String subject, String message)
MailProvider getProvider()
MailMessage addToPoolTemplate(String from, String to, String cc, String subject, String message, String template, String name, String login)
static MailQueueConsumer getInstance()
void addToQueue(Collection< MailMessage > pool)
Object put(Object key, Object value)