Package org.javlo.mailing
Class MailService
- java.lang.Object
-
- org.javlo.mailing.MailService
-
public class MailService extends Object
This class, working in a singleton mode, is a utility for sending mail messages.- Author:
- pvandermaesen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MailService.Attachment
-
Field Summary
Fields Modifier and Type Field Description static String
HIDDEN_DIV
protected static Logger
logger
create a static logger.static String
MAILING_ID_MAIL_KEY
static String
SMTP_HOST_PARAM
static String
SMTP_PASSWORD_PARAM
static String
SMTP_PORT_PARAM
static String
SMTP_USER_PARAM
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
_messageToDKIMBody(javax.mail.internet.MimeMultipart part)
static String
getDefaultReceiverEmail(ContentContext ctx, String email)
get the default mail receiver.static String
getDefaultSenderEmail(ContentContext ctx, String email)
get the default mail sender.static MailService
getInstance(MailConfig mailConfig)
This method is kept to be able to use this class outside a Servlet contextMailConfig
getMailConfig()
static javax.mail.Session
getMailSession(MailConfig mailConfig)
static List<MenuElement>
getMailTemplate(ContentContext ctx)
static MenuElement
getMailTemplateParentPage(ContentContext ctx)
static javax.mail.Transport
getMailTransport(MailConfig mailConfig)
static void
main(String[] args)
static String
messageToDKIMBody(javax.mail.internet.MimeMultipart msg, OutputStream out)
static String
messageToText(javax.mail.internet.MimeMultipart part)
static void
resetInstance()
void
sendMail(javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML)
void
sendMail(javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML, DKIMBean dkim)
void
sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML, String unsubribeLink)
Send one mail to one recipient.String
sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML, String unsubribeLink, DKIMBean dkinBean, String mailId)
String
sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, List<javax.mail.internet.InternetAddress> ccRecipients, List<javax.mail.internet.InternetAddress> bccRecipients, String subject, String content, boolean isHTML, String unsubribeLink, DKIMBean dkinBean)
Send one mail to one recipient and multiple BCC recipients (in one mail).void
sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, javax.mail.internet.InternetAddress ccRecipient, javax.mail.internet.InternetAddress bccRecipient, String subject, String content, boolean isHTML)
void
sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, javax.mail.internet.InternetAddress ccRecipient, javax.mail.internet.InternetAddress bccRecipient, String subject, String content, String contentTxt, boolean isHTML, DKIMBean dkimBean)
String
sendMail(javax.mail.Transport transport, EMail email)
void
sendMail(GlobalContext globalContext, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML)
String
sendMail(EMail email)
void
sendMailAsyncron(javax.mail.Transport transport, EMail email)
void
sendMailAsyncron(EMail email)
static void
writeEMLFile(String subject, String body, OutputStream out)
-
-
-
Field Detail
-
HIDDEN_DIV
public static final String HIDDEN_DIV
- See Also:
- Constant Field Values
-
MAILING_ID_MAIL_KEY
public static final String MAILING_ID_MAIL_KEY
- See Also:
- Constant Field Values
-
SMTP_HOST_PARAM
public static final String SMTP_HOST_PARAM
- See Also:
- Constant Field Values
-
SMTP_PORT_PARAM
public static final String SMTP_PORT_PARAM
- See Also:
- Constant Field Values
-
SMTP_USER_PARAM
public static final String SMTP_USER_PARAM
- See Also:
- Constant Field Values
-
SMTP_PASSWORD_PARAM
public static final String SMTP_PASSWORD_PARAM
- See Also:
- Constant Field Values
-
logger
protected static Logger logger
create a static logger.
-
-
Method Detail
-
getInstance
public static MailService getInstance(MailConfig mailConfig)
This method is kept to be able to use this class outside a Servlet context- Parameters:
mailConfig
- config for mailing.- Returns:
- the MailingManager singleton
-
getMailSession
public static final javax.mail.Session getMailSession(MailConfig mailConfig) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
getMailTransport
public static final javax.mail.Transport getMailTransport(MailConfig mailConfig) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMail
public String sendMail(EMail email) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMailAsyncron
public void sendMailAsyncron(EMail email)
-
sendMailAsyncron
public void sendMailAsyncron(javax.mail.Transport transport, EMail email)
-
sendMail
public String sendMail(javax.mail.Transport transport, EMail email) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMail
public String sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, List<javax.mail.internet.InternetAddress> ccRecipients, List<javax.mail.internet.InternetAddress> bccRecipients, String subject, String content, boolean isHTML, String unsubribeLink, DKIMBean dkinBean) throws javax.mail.MessagingException
Send one mail to one recipient and multiple BCC recipients (in one mail).- Parameters:
transport
- transport connection, if null transport is create inside the methodsender
- the "From" fieldrecipient
- the "To" fieldbccRecipients
- the "Bcc" field with multiple addresses.subject
- the Subject of the messagecontent
- the Content of the messageisHTML
- flag indicating wether the Content is html (true
) or text (false
)- Throws:
javax.mail.MessagingException
- Forwarded exception from javax.mailIllegalArgumentException
- if no recipient provided or no sender
-
sendMail
public void sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, javax.mail.internet.InternetAddress ccRecipient, javax.mail.internet.InternetAddress bccRecipient, String subject, String content, boolean isHTML) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMail
public void sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, javax.mail.internet.InternetAddress ccRecipient, javax.mail.internet.InternetAddress bccRecipient, String subject, String content, String contentTxt, boolean isHTML, DKIMBean dkimBean) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
getMailConfig
public MailConfig getMailConfig()
-
sendMail
public void sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML, String unsubribeLink) throws javax.mail.MessagingException
Send one mail to one recipient.- Parameters:
transport
- transport connection, if null transport is create inside the methodsender
- the "From" fieldrecipient
- the "To" fieldsubject
- the Subject of the messagecontent
- the Content of the messageisHTML
- flag indicating wether the Content is html (true
) or text (false
)- Throws:
javax.mail.MessagingException
- Forwarded exception from javax.mailIllegalArgumentException
- if no recipient provided or no sender
-
sendMail
public String sendMail(javax.mail.Transport transport, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML, String unsubribeLink, DKIMBean dkinBean, String mailId) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMail
public void sendMail(javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMail
public void sendMail(javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML, DKIMBean dkim) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
sendMail
public void sendMail(GlobalContext globalContext, javax.mail.internet.InternetAddress sender, javax.mail.internet.InternetAddress recipient, String subject, String content, boolean isHTML) throws javax.mail.MessagingException
- Throws:
javax.mail.MessagingException
-
resetInstance
public static void resetInstance()
-
messageToText
public static String messageToText(javax.mail.internet.MimeMultipart part) throws IOException, javax.mail.MessagingException
- Throws:
IOException
javax.mail.MessagingException
-
messageToDKIMBody
public static String messageToDKIMBody(javax.mail.internet.MimeMultipart msg, OutputStream out) throws IOException, javax.mail.MessagingException
- Throws:
IOException
javax.mail.MessagingException
-
_messageToDKIMBody
public static String _messageToDKIMBody(javax.mail.internet.MimeMultipart part) throws IOException, javax.mail.MessagingException
- Throws:
IOException
javax.mail.MessagingException
-
writeEMLFile
public static void writeEMLFile(String subject, String body, OutputStream out) throws javax.mail.MessagingException, IOException
- Throws:
javax.mail.MessagingException
IOException
-
getMailTemplateParentPage
public static MenuElement getMailTemplateParentPage(ContentContext ctx) throws Exception
- Throws:
Exception
-
getMailTemplate
public static List<MenuElement> getMailTemplate(ContentContext ctx) throws Exception
- Throws:
Exception
-
getDefaultSenderEmail
public static String getDefaultSenderEmail(ContentContext ctx, String email)
get the default mail sender.- Parameters:
ctx
-email
-- Returns:
- if email is a email return it
-
getDefaultReceiverEmail
public static String getDefaultReceiverEmail(ContentContext ctx, String email)
get the default mail receiver.- Parameters:
ctx
-email
-- Returns:
- if email is a email return it
-
-