Package com.saperion.common.mail
Class Mailing
- java.lang.Object
-
- com.saperion.common.mail.Mailing
-
public class Mailing extends java.lang.Object
A mail util class for convenient SMTP mailing.
This implementation is not synchronized. If used by different threads concurrently, external synchronization is necessary.
- Author:
- sts
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROTOCOL_SMTP
static java.lang.String
PROTOCOL_SMTPS
-
Constructor Summary
Constructors Constructor Description Mailing(MailConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isInitialized()
Indicates if this instance was initialized properly and can be used.void
sendMail(java.lang.String fromAddress, java.lang.String fromName, java.lang.String to, java.lang.String subject, java.lang.String text)
Sends a mail by the given parameters.void
testSmtpConnect()
Performs a test SMTP connect.
-
-
-
Field Detail
-
PROTOCOL_SMTP
public static final java.lang.String PROTOCOL_SMTP
- See Also:
- Constant Field Values
-
PROTOCOL_SMTPS
public static final java.lang.String PROTOCOL_SMTPS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Mailing
public Mailing(MailConfiguration configuration) throws MailConfigurationException
- Throws:
MailConfigurationException
-
-
Method Detail
-
testSmtpConnect
public void testSmtpConnect() throws javax.mail.MessagingException
Performs a test SMTP connect. This can be done to test, if the mail configuration is correct. No mail is send, only a connect is performed.- Throws:
javax.mail.MessagingException
- if the test-connect did not succeed.
-
isInitialized
public boolean isInitialized()
Indicates if this instance was initialized properly and can be used. Note: this indication does only mean that a SMTP session could be created with the present configuration. If you want to check if a SMTP connect is working, please call the methodtestSMTPConnect
.- Returns:
- true, if this instance was initialized properly, false otherwise.
-
sendMail
public void sendMail(java.lang.String fromAddress, java.lang.String fromName, java.lang.String to, java.lang.String subject, java.lang.String text) throws javax.mail.MessagingException, java.io.UnsupportedEncodingException, MailConfigurationException
Sends a mail by the given parameters. The mail content is encoded as "text/html" in "utf-8" always.- Parameters:
fromAddress
- the sender's mail address. May not be null or empty.fromName
- the sender's name. May not be null or empty.to
- the receiver's mail address. May not be null or empty.subject
- the mail subject. May not be null or empty.text
- the mail body. May not be null or empty.- Throws:
javax.mail.MessagingException
- if the mail could not be sent.java.io.UnsupportedEncodingException
- if the mail could not be sent due to an EncodingException.MailConfigurationException
- if this instance was not initialized properly.
-
-