Package psiprobe.tools
Class Mailer
- java.lang.Object
-
- psiprobe.tools.Mailer
-
public class Mailer extends Object
Facade for sending emails with the JavaMail API.
-
-
Field Summary
Fields Modifier and Type Field Description private String
defaultTo
The default to.private String
from
The from.private static org.slf4j.Logger
logger
The Constant logger.static String
PROPERTY_KEY_SMTP
The Constant PROPERTY_KEY_SMTP.private String
smtp
The smtp.private String
subjectPrefix
The subject prefix.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static javax.mail.internet.InternetAddress[]
createAddresses(String[] addresses)
Creates the addresses.private static javax.mail.internet.MimeBodyPart
createAttachmentPart(DataSource attachment)
Creates the attachment part.private static javax.mail.internet.MimeBodyPart
createMessageBodyPart(String body, boolean html)
Creates the message body part.private javax.mail.internet.MimeMessage
createMimeMessage(javax.mail.Session session, MailMessage mailMessage)
Creates the mime message.String
getDefaultTo()
Gets the default to.String
getFrom()
Gets the from.String
getSmtp()
Gets the smtp.String
getSubjectPrefix()
Gets the subject prefix.void
send(MailMessage mailMessage)
Send.void
setDefaultTo(String defaultTo)
Sets the default to.void
setFrom(String from)
Sets the from.void
setSmtp(String smtp)
Sets the smtp.void
setSubjectPrefix(String subjectPrefix)
Sets the subject prefix.
-
-
-
Field Detail
-
PROPERTY_KEY_SMTP
public static final String PROPERTY_KEY_SMTP
The Constant PROPERTY_KEY_SMTP.- See Also:
- Constant Field Values
-
logger
private static final org.slf4j.Logger logger
The Constant logger.
-
from
private String from
The from.
-
smtp
private String smtp
The smtp.
-
defaultTo
private String defaultTo
The default to.
-
subjectPrefix
private String subjectPrefix
The subject prefix.
-
-
Method Detail
-
getFrom
public String getFrom()
Gets the from.- Returns:
- the from
-
getSmtp
public String getSmtp()
Gets the smtp.- Returns:
- the smtp
-
setFrom
public void setFrom(String from)
Sets the from.- Parameters:
from
- the new from
-
setSmtp
public void setSmtp(String smtp)
Sets the smtp.- Parameters:
smtp
- the new smtp
-
getDefaultTo
public String getDefaultTo()
Gets the default to.- Returns:
- the default to
-
setDefaultTo
@Value("${psiprobe.tools.mail.to}") public void setDefaultTo(String defaultTo)
Sets the default to.- Parameters:
defaultTo
- the new default to
-
getSubjectPrefix
public String getSubjectPrefix()
Gets the subject prefix.- Returns:
- the subject prefix
-
setSubjectPrefix
@Value("${psiprobe.tools.mail.subjectPrefix}") public void setSubjectPrefix(String subjectPrefix)
Sets the subject prefix.- Parameters:
subjectPrefix
- the new subject prefix
-
send
public void send(MailMessage mailMessage) throws javax.mail.MessagingException
Send.- Parameters:
mailMessage
- the mail message- Throws:
javax.mail.MessagingException
- the messaging exception
-
createMimeMessage
private javax.mail.internet.MimeMessage createMimeMessage(javax.mail.Session session, MailMessage mailMessage) throws javax.mail.MessagingException
Creates the mime message.- Parameters:
session
- the sessionmailMessage
- the mail message- Returns:
- the mime message
- Throws:
javax.mail.MessagingException
- the messaging exception
-
createAddresses
private static javax.mail.internet.InternetAddress[] createAddresses(String[] addresses) throws javax.mail.internet.AddressException
Creates the addresses.- Parameters:
addresses
- the addresses- Returns:
- the Internet address[]
- Throws:
javax.mail.internet.AddressException
- the address exception
-
createAttachmentPart
private static javax.mail.internet.MimeBodyPart createAttachmentPart(DataSource attachment) throws javax.mail.MessagingException
Creates the attachment part.- Parameters:
attachment
- the attachment- Returns:
- the mime body part
- Throws:
javax.mail.MessagingException
- the messaging exception
-
createMessageBodyPart
private static javax.mail.internet.MimeBodyPart createMessageBodyPart(String body, boolean html) throws javax.mail.MessagingException
Creates the message body part.- Parameters:
body
- the bodyhtml
- the html- Returns:
- the mime body part
- Throws:
javax.mail.MessagingException
- the messaging exception
-
-