Class Email
- java.lang.Object
-
- org.apache.commons.mail.Email
-
- Direct Known Subclasses:
MultiPartEmail,SimpleEmail
public abstract class Email extends java.lang.Object
The abstract class for all email messages. This class sets the sender's email, name, receiver's email, name, subject, and send date.Subclasses are responsible for setting the message body.
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTACHMENTSDeprecated.since 1.3, useEmailConstants.ATTACHMENTSinsteadprotected javax.mail.AuthenticatorauthenticatorDeprecated.Use getters and getters.protected java.util.List<javax.mail.internet.InternetAddress>bccListDeprecated.Use getters and getters.protected java.lang.StringbounceAddressDeprecated.Use getters and getters.protected java.util.List<javax.mail.internet.InternetAddress>ccListDeprecated.Use getters and getters.protected java.lang.StringcharsetDeprecated.Use getters and getters.protected java.lang.ObjectcontentDeprecated.Use getters and getters.static java.lang.StringCONTENT_TYPEDeprecated.since 1.3, useEmailConstants.CONTENT_TYPEinsteadprotected java.lang.StringcontentTypeDeprecated.Use getters and getters.protected booleandebugDeprecated.Use getters and getters.static java.lang.StringEMAIL_BODYDeprecated.since 1.3, useEmailConstants.EMAIL_BODYinsteadstatic java.lang.StringEMAIL_SUBJECTDeprecated.since 1.3, useEmailConstants.EMAIL_SUBJECTinsteadprotected javax.mail.internet.MimeMultipartemailBodyDeprecated.Use getters and getters.static java.lang.StringFILE_SERVERDeprecated.since 1.3, useEmailConstants.FILE_SERVERinsteadprotected javax.mail.internet.InternetAddressfromAddressDeprecated.Use getters and getters.protected java.util.Map<java.lang.String,java.lang.String>headersDeprecated.Use getters and getters.protected java.lang.StringhostNameDeprecated.Use getters and getters.static java.lang.StringISO_8859_1Deprecated.since 1.3, useEmailConstants.ISO_8859_1insteadstatic java.lang.StringKOI8_RDeprecated.since 1.3, useEmailConstants.KOI8_Rinsteadstatic java.lang.StringMAIL_DEBUGDeprecated.since 1.3, useEmailConstants.MAIL_DEBUGinsteadstatic java.lang.StringMAIL_HOSTDeprecated.since 1.3, useEmailConstants.MAIL_HOSTinsteadstatic java.lang.StringMAIL_PORTDeprecated.since 1.3, useEmailConstants.MAIL_PORTinsteadstatic java.lang.StringMAIL_SMTP_AUTHDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_AUTHinsteadstatic java.lang.StringMAIL_SMTP_CONNECTIONTIMEOUTDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_CONNECTIONTIMEOUTinsteadstatic java.lang.StringMAIL_SMTP_FROMDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_FROMinsteadstatic java.lang.StringMAIL_SMTP_PASSWORDDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_PASSWORDinsteadstatic java.lang.StringMAIL_SMTP_SOCKET_FACTORY_CLASSDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_SOCKET_FACTORY_CLASSinsteadstatic java.lang.StringMAIL_SMTP_SOCKET_FACTORY_FALLBACKDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_SOCKET_FACTORY_FALLBACKinsteadstatic java.lang.StringMAIL_SMTP_SOCKET_FACTORY_PORTDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_SOCKET_FACTORY_PORTinsteadstatic java.lang.StringMAIL_SMTP_TIMEOUTDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_TIMEOUTinsteadstatic java.lang.StringMAIL_SMTP_USERDeprecated.since 1.3, useEmailConstants.MAIL_SMTP_USERinsteadstatic java.lang.StringMAIL_TRANSPORT_PROTOCOLDeprecated.since 1.3, useEmailConstants.MAIL_TRANSPORT_PROTOCOLinsteadstatic java.lang.StringMAIL_TRANSPORT_TLSDeprecated.since 1.3, useEmailConstants.MAIL_TRANSPORT_TLSinsteadprotected javax.mail.internet.MimeMessagemessageDeprecated.Use getters and getters.protected booleanpopBeforeSmtpDeprecated.Use getters and getters.protected java.lang.StringpopHostDeprecated.Use getters and getters.protected java.lang.StringpopPasswordDeprecated.Use getters and getters.protected java.lang.StringpopUsernameDeprecated.Use getters and getters.static java.lang.StringRECEIVER_EMAILDeprecated.since 1.3, useEmailConstants.RECEIVER_EMAILinsteadstatic java.lang.StringRECEIVER_NAMEDeprecated.since 1.3, useEmailConstants.RECEIVER_NAMEinsteadprotected java.util.List<javax.mail.internet.InternetAddress>replyListDeprecated.Use getters and getters.static java.lang.StringSENDER_EMAILDeprecated.since 1.3, useEmailConstants.SENDER_EMAILinsteadstatic java.lang.StringSENDER_NAMEDeprecated.since 1.3, useEmailConstants.SENDER_NAMEinsteadprotected java.util.DatesentDateDeprecated.Use getters and getters.static java.lang.StringSMTPDeprecated.since 1.3, useEmailConstants.SMTPinsteadprotected java.lang.StringsmtpPortDeprecated.Use getters and getters.protected intsocketConnectionTimeoutDeprecated.protected intsocketTimeoutDeprecated.protected booleansslDeprecated.since 1.3, use setSSLOnConnect() insteadprotected java.lang.StringsslSmtpPortDeprecated.Use getters and getters.protected java.lang.StringsubjectDeprecated.Use getters and getters.static java.lang.StringTEXT_HTMLDeprecated.since 1.3, useEmailConstants.TEXT_HTMLinsteadstatic java.lang.StringTEXT_PLAINDeprecated.since 1.3, useEmailConstants.TEXT_PLAINinsteadprotected booleantlsDeprecated.since 1.3, use setStartTLSEnabled() insteadprotected java.util.List<javax.mail.internet.InternetAddress>toListDeprecated.Use getters and getters.static java.lang.StringUS_ASCIIDeprecated.since 1.3, useEmailConstants.US_ASCIIinstead
-
Constructor Summary
Constructors Constructor Description Email()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description EmailaddBcc(java.lang.String email)Adds a blind BCC recipient to the email.EmailaddBcc(java.lang.String... emails)Adds an array of blind BCC recipients to the email.EmailaddBcc(java.lang.String email, java.lang.String name)Adds a blind BCC recipient to the email using the specified address and the specified personal name.EmailaddBcc(java.lang.String email, java.lang.String name, java.lang.String charset)Adds a blind BCC recipient to the email using the specified address, personal name, and charset encoding for the name.EmailaddCc(java.lang.String email)Adds a recipient CC to the email.EmailaddCc(java.lang.String... emails)Adds an array of CC recipients to the email.EmailaddCc(java.lang.String email, java.lang.String name)Adds a recipient CC to the email using the specified address and the specified personal name.EmailaddCc(java.lang.String email, java.lang.String name, java.lang.String charset)Adds a recipient CC to the email using the specified address, personal name, and charset encoding for the name.voidaddHeader(java.lang.String name, java.lang.String value)Adds a header ( name, value ) to the headers Map.EmailaddReplyTo(java.lang.String email)Adds a reply to address to the email.EmailaddReplyTo(java.lang.String email, java.lang.String name)Adds a reply to address to the email using the specified address and the specified personal name.EmailaddReplyTo(java.lang.String email, java.lang.String name, java.lang.String charset)Adds a reply to address to the email using the specified address, personal name, and charset encoding for the name.EmailaddTo(java.lang.String email)Adds a recipient TO to the email.EmailaddTo(java.lang.String... emails)Adds a list of TO recipients to the email.EmailaddTo(java.lang.String email, java.lang.String name)Adds a recipient TO to the email using the specified address and the specified personal name.EmailaddTo(java.lang.String email, java.lang.String name, java.lang.String charset)Adds a recipient TO to the email using the specified address, personal name, and charset encoding for the name.voidbuildMimeMessage()Builds the MimeMessage.protected javax.mail.internet.MimeMessagecreateMimeMessage(javax.mail.Session aSession)Creates a customized MimeMessage which can be implemented by a derived class, e.g.javax.mail.AuthenticatorgetAuthenticator()Gets the authenticator.java.util.List<javax.mail.internet.InternetAddress>getBccAddresses()Gets the list of "Bcc" addresses.java.lang.StringgetBounceAddress()Gets the "bounce address" of this email.java.util.List<javax.mail.internet.InternetAddress>getCcAddresses()Gets the list of "CC" addresses.java.lang.StringgetCharsetName()Gets the Charset.java.lang.ObjectgetContent()Gets the content.java.lang.StringgetContentType()Gets the content type.javax.mail.internet.MimeMultipartgetEmailBody()Gets the email body.javax.mail.internet.InternetAddressgetFromAddress()Gets the sender of the email.java.lang.StringgetHeader(java.lang.String header)Gets the specified header.java.util.Map<java.lang.String,java.lang.String>getHeaders()Gets all headers on an Email.java.lang.StringgetHostName()Gets the host name of the SMTP server,javax.mail.SessiongetMailSession()Gets the mail session used when sending this Email, creating the Session if necessary.javax.mail.internet.MimeMessagegetMessage()Gets the message.javax.mail.internet.MimeMessagegetMimeMessage()Gets the internal MimeMessage.java.lang.StringgetPopHost()Gets the POP3 host.java.lang.StringgetPopPassword()Gets the POP3 password.java.lang.StringgetPopUserName()Gets the POP3 user name.java.util.List<javax.mail.internet.InternetAddress>getReplyToAddresses()Gets the list of "Reply-To" addresses.java.util.DategetSentDate()Gets the sent date for the email.java.lang.StringgetSmtpPort()Gets the listening port of the SMTP server.intgetSocketConnectionTimeout()Gets the socket connection timeout value in milliseconds.intgetSocketTimeout()Gets the socket I/O timeout value in milliseconds.java.lang.StringgetSslSmtpPort()Gets the current SSL port used by the SMTP transport.java.lang.StringgetSubject()Gets the subject of the email.java.util.List<javax.mail.internet.InternetAddress>getToAddresses()Gets the list of "To" addresses.booleanisDebug()Tests whether debug is on.booleanisPopBeforeSmtp()Tests whether to use POP3 before SMTP, and if so the settings.booleanisSendPartial()Tests whether partial sending of email is enabled.booleanisSSL()Deprecated.since 1.3, useisSSLOnConnect()instead.booleanisSSLCheckServerIdentity()Tests whether the server identity checked as specified by RFC 2595booleanisSSLOnConnect()Tests whether SSL/TLS encryption for the transport is currently enabled (SMTPS/POPS).booleanisStartTLSEnabled()Tests whether the client is configured to try to enable STARTTLS.booleanisStartTLSRequired()Tests whether the client is configured to require STARTTLS.booleanisTLS()Deprecated.since 1.3, useisStartTLSEnabled()instead.java.lang.Stringsend()Sends the email.java.lang.StringsendMimeMessage()Sends the previously created MimeMessage to the SMTP server.voidsetAuthentication(java.lang.String userName, java.lang.String password)Sets the userName and password if authentication is needed.voidsetAuthenticator(javax.mail.Authenticator authenticator)Sets theAuthenticatorto be used when authentication is requested from the mail server.EmailsetBcc(java.util.Collection<javax.mail.internet.InternetAddress> collection)Sets a list of "BCC" addresses.EmailsetBounceAddress(java.lang.String email)Sets the "bounce address" - the address to which undeliverable messages will be returned.EmailsetCc(java.util.Collection<javax.mail.internet.InternetAddress> collection)Sets a list of "CC" addresses.voidsetCharset(java.lang.String charset)Sets the charset of the message.EmailsetContent(java.lang.Object content)Sets the content.voidsetContent(java.lang.Object content, java.lang.String contentType)Sets the content and contentType.voidsetContent(javax.mail.internet.MimeMultipart mimeMultipart)Sets the emailBody to a MimeMultiPartEmailsetContentType(java.lang.String contentType)Sets the content type.voidsetDebug(boolean debug)Sets the display of debug information.EmailsetFrom(java.lang.String email)Sets the FROM field of the email to use the specified address.EmailsetFrom(java.lang.String email, java.lang.String name)Sets the FROM field of the email to use the specified address and the specified personal name.EmailsetFrom(java.lang.String email, java.lang.String name, java.lang.String charset)Sets the FROM field of the email to use the specified address, personal name, and charset encoding for the name.EmailsetFromAddress(javax.mail.internet.InternetAddress fromAddress)Sets the From address.voidsetHeaders(java.util.Map<java.lang.String,java.lang.String> map)Sets the mail headers.voidsetHostName(java.lang.String hostName)Sets the hostname of the outgoing mail server.voidsetMailSession(javax.mail.Session session)Sets a mail Session object to use.voidsetMailSessionFromJNDI(java.lang.String jndiName)Sets a mail Session object from a JNDI directory.voidsetMessage(javax.mail.internet.MimeMessage message)Sets the MIME message.abstract EmailsetMsg(java.lang.String msg)Sets the content of the mail.EmailsetPopBeforeSmtp(boolean popBeforeSmtp)Sets whether to use POP3 before SMTP, and if so the settings.voidsetPopBeforeSmtp(boolean popBeforeSmtp, java.lang.String popHost, java.lang.String popUserName, java.lang.String popPassword)Sets details regarding "POP3 before SMTP" authentication.EmailsetPopHost(java.lang.String popHost)Sets the POP3 host.EmailsetPopPassword(java.lang.String popPassword)Sets the POP3 password.EmailsetPopUsername(java.lang.String popUserName)Sets the POP3 user name.EmailsetReplyTo(java.util.Collection<javax.mail.internet.InternetAddress> collection)Sets a list of reply to addresses.EmailsetSendPartial(boolean sendPartial)Sets whether the email is partially send in case of invalid addresses.voidsetSentDate(java.util.Date date)Sets the sent date for the email.voidsetSmtpPort(int portNumber)Sets the non-SSL port number of the outgoing mail server.voidsetSocketConnectionTimeout(int socketConnectionTimeout)Deprecated.voidsetSocketConnectionTimeout(java.time.Duration socketConnectionTimeout)Sets the socket connection timeout value in milliseconds.voidsetSocketTimeout(int socketTimeout)Deprecated.voidsetSocketTimeout(java.time.Duration socketTimeout)Sets the socket I/O timeout value in milliseconds.voidsetSSL(boolean ssl)Deprecated.since 1.3, usesetSSLOnConnect(boolean)instead.EmailsetSSLCheckServerIdentity(boolean sslCheckServerIdentity)Sets whether the server identity is checked as specified by RFC 2595EmailsetSSLOnConnect(boolean ssl)Sets whether SSL/TLS encryption should be enabled for the SMTP transport upon connection (SMTPS/POPS).voidsetSslSmtpPort(java.lang.String sslSmtpPort)Sets the SSL port to use for the SMTP transport.EmailsetStartTLSEnabled(boolean startTlsEnabled)Sets or disable the STARTTLS encryption.EmailsetStartTLSRequired(boolean startTlsRequired)Sets or disable the required STARTTLS encryption.EmailsetSubject(java.lang.String aSubject)Sets the email subject.voidsetTLS(boolean withTLS)Deprecated.since 1.3, usesetStartTLSEnabled(boolean)instead.EmailsetTo(java.util.Collection<javax.mail.internet.InternetAddress> collection)Sets a list of "TO" addresses.protected javax.mail.internet.InternetAddress[]toInternetAddressArray(java.util.List<javax.mail.internet.InternetAddress> list)Converts to copy List of known InternetAddress objects into an array.voidupdateContentType(java.lang.String contentType)Updates the contentType.
-
-
-
Field Detail
-
SENDER_EMAIL
@Deprecated public static final java.lang.String SENDER_EMAIL
Deprecated.since 1.3, useEmailConstants.SENDER_EMAILinstead- See Also:
- Constant Field Values
-
SENDER_NAME
@Deprecated public static final java.lang.String SENDER_NAME
Deprecated.since 1.3, useEmailConstants.SENDER_NAMEinstead- See Also:
- Constant Field Values
-
RECEIVER_EMAIL
@Deprecated public static final java.lang.String RECEIVER_EMAIL
Deprecated.since 1.3, useEmailConstants.RECEIVER_EMAILinstead- See Also:
- Constant Field Values
-
RECEIVER_NAME
@Deprecated public static final java.lang.String RECEIVER_NAME
Deprecated.since 1.3, useEmailConstants.RECEIVER_NAMEinstead- See Also:
- Constant Field Values
-
EMAIL_SUBJECT
@Deprecated public static final java.lang.String EMAIL_SUBJECT
Deprecated.since 1.3, useEmailConstants.EMAIL_SUBJECTinstead- See Also:
- Constant Field Values
-
EMAIL_BODY
@Deprecated public static final java.lang.String EMAIL_BODY
Deprecated.since 1.3, useEmailConstants.EMAIL_BODYinstead- See Also:
- Constant Field Values
-
CONTENT_TYPE
@Deprecated public static final java.lang.String CONTENT_TYPE
Deprecated.since 1.3, useEmailConstants.CONTENT_TYPEinstead- See Also:
- Constant Field Values
-
ATTACHMENTS
@Deprecated public static final java.lang.String ATTACHMENTS
Deprecated.since 1.3, useEmailConstants.ATTACHMENTSinstead- See Also:
- Constant Field Values
-
FILE_SERVER
@Deprecated public static final java.lang.String FILE_SERVER
Deprecated.since 1.3, useEmailConstants.FILE_SERVERinstead- See Also:
- Constant Field Values
-
KOI8_R
@Deprecated public static final java.lang.String KOI8_R
Deprecated.since 1.3, useEmailConstants.KOI8_Rinstead- See Also:
- Constant Field Values
-
ISO_8859_1
@Deprecated public static final java.lang.String ISO_8859_1
Deprecated.since 1.3, useEmailConstants.ISO_8859_1instead
-
US_ASCII
@Deprecated public static final java.lang.String US_ASCII
Deprecated.since 1.3, useEmailConstants.US_ASCIIinstead
-
MAIL_DEBUG
@Deprecated public static final java.lang.String MAIL_DEBUG
Deprecated.since 1.3, useEmailConstants.MAIL_DEBUGinstead- See Also:
- Constant Field Values
-
MAIL_HOST
@Deprecated public static final java.lang.String MAIL_HOST
Deprecated.since 1.3, useEmailConstants.MAIL_HOSTinstead- See Also:
- Constant Field Values
-
MAIL_PORT
@Deprecated public static final java.lang.String MAIL_PORT
Deprecated.since 1.3, useEmailConstants.MAIL_PORTinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_FROM
@Deprecated public static final java.lang.String MAIL_SMTP_FROM
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_FROMinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_AUTH
@Deprecated public static final java.lang.String MAIL_SMTP_AUTH
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_AUTHinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_USER
@Deprecated public static final java.lang.String MAIL_SMTP_USER
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_USERinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_PASSWORD
@Deprecated public static final java.lang.String MAIL_SMTP_PASSWORD
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_PASSWORDinstead- See Also:
- Constant Field Values
-
MAIL_TRANSPORT_PROTOCOL
@Deprecated public static final java.lang.String MAIL_TRANSPORT_PROTOCOL
Deprecated.since 1.3, useEmailConstants.MAIL_TRANSPORT_PROTOCOLinstead- See Also:
- Constant Field Values
-
SMTP
@Deprecated public static final java.lang.String SMTP
Deprecated.since 1.3, useEmailConstants.SMTPinstead- See Also:
- Constant Field Values
-
TEXT_HTML
@Deprecated public static final java.lang.String TEXT_HTML
Deprecated.since 1.3, useEmailConstants.TEXT_HTMLinstead- See Also:
- Constant Field Values
-
TEXT_PLAIN
@Deprecated public static final java.lang.String TEXT_PLAIN
Deprecated.since 1.3, useEmailConstants.TEXT_PLAINinstead- See Also:
- Constant Field Values
-
MAIL_TRANSPORT_TLS
@Deprecated public static final java.lang.String MAIL_TRANSPORT_TLS
Deprecated.since 1.3, useEmailConstants.MAIL_TRANSPORT_TLSinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_SOCKET_FACTORY_FALLBACK
@Deprecated public static final java.lang.String MAIL_SMTP_SOCKET_FACTORY_FALLBACK
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_SOCKET_FACTORY_FALLBACKinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_SOCKET_FACTORY_CLASS
@Deprecated public static final java.lang.String MAIL_SMTP_SOCKET_FACTORY_CLASS
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_SOCKET_FACTORY_CLASSinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_SOCKET_FACTORY_PORT
@Deprecated public static final java.lang.String MAIL_SMTP_SOCKET_FACTORY_PORT
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_SOCKET_FACTORY_PORTinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_CONNECTIONTIMEOUT
@Deprecated public static final java.lang.String MAIL_SMTP_CONNECTIONTIMEOUT
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_CONNECTIONTIMEOUTinstead- See Also:
- Constant Field Values
-
MAIL_SMTP_TIMEOUT
@Deprecated public static final java.lang.String MAIL_SMTP_TIMEOUT
Deprecated.since 1.3, useEmailConstants.MAIL_SMTP_TIMEOUTinstead- See Also:
- Constant Field Values
-
message
@Deprecated protected javax.mail.internet.MimeMessage message
Deprecated.Use getters and getters.The email message to send.
-
charset
@Deprecated protected java.lang.String charset
Deprecated.Use getters and getters.The charset to use for this message.
-
fromAddress
@Deprecated protected javax.mail.internet.InternetAddress fromAddress
Deprecated.Use getters and getters.The Address of the sending party, mandatory.
-
subject
@Deprecated protected java.lang.String subject
Deprecated.Use getters and getters.The Subject.
-
emailBody
@Deprecated protected javax.mail.internet.MimeMultipart emailBody
Deprecated.Use getters and getters.An attachment.
-
content
@Deprecated protected java.lang.Object content
Deprecated.Use getters and getters.The content.
-
contentType
@Deprecated protected java.lang.String contentType
Deprecated.Use getters and getters.The content type.
-
debug
@Deprecated protected boolean debug
Deprecated.Use getters and getters.Set session debugging on or off.
-
sentDate
@Deprecated protected java.util.Date sentDate
Deprecated.Use getters and getters.Sent date.
-
authenticator
@Deprecated protected javax.mail.Authenticator authenticator
Deprecated.Use getters and getters.Instance of anAuthenticatorobject that will be used when authentication is requested from the mail server.
-
hostName
@Deprecated protected java.lang.String hostName
Deprecated.Use getters and getters.The hostname of the mail server with which to connect. If null will try to get property from system.properties. If still null, quit.
-
smtpPort
@Deprecated protected java.lang.String smtpPort
Deprecated.Use getters and getters.The port number of the mail server to connect to. Defaults to the standard port ( 25 ).
-
sslSmtpPort
@Deprecated protected java.lang.String sslSmtpPort
Deprecated.Use getters and getters.The port number of the SSL enabled SMTP server; defaults to the standard port, 465.
-
toList
@Deprecated protected java.util.List<javax.mail.internet.InternetAddress> toList
Deprecated.Use getters and getters.List of "to" email addresses.
-
ccList
@Deprecated protected java.util.List<javax.mail.internet.InternetAddress> ccList
Deprecated.Use getters and getters.List of "cc" email addresses.
-
bccList
@Deprecated protected java.util.List<javax.mail.internet.InternetAddress> bccList
Deprecated.Use getters and getters.List of "bcc" email addresses.
-
replyList
@Deprecated protected java.util.List<javax.mail.internet.InternetAddress> replyList
Deprecated.Use getters and getters.List of "replyTo" email addresses.
-
bounceAddress
@Deprecated protected java.lang.String bounceAddress
Deprecated.Use getters and getters.Address to which undeliverable mail should be sent. Because this is handled by JavaMail as a String property in the mail session, this property is of typeStringrather thanInternetAddress.
-
headers
@Deprecated protected java.util.Map<java.lang.String,java.lang.String> headers
Deprecated.Use getters and getters.Used to specify the mail headers. Example: X-Mailer: Sendmail, X-Priority: 1( highest ) or 2( high ) 3( normal ) 4( low ) and 5( lowest ) Disposition-Notification-To: user@domain.net
-
popBeforeSmtp
@Deprecated protected boolean popBeforeSmtp
Deprecated.Use getters and getters.Whether to use POP3 before SMTP, and if so the settings.
-
popHost
@Deprecated protected java.lang.String popHost
Deprecated.Use getters and getters.The host name of the POP3 server.
-
popUsername
@Deprecated protected java.lang.String popUsername
Deprecated.Use getters and getters.The user name to log into the POP3 server.
-
popPassword
@Deprecated protected java.lang.String popPassword
Deprecated.Use getters and getters.The password to log into the POP3 server.
-
tls
@Deprecated protected boolean tls
Deprecated.since 1.3, use setStartTLSEnabled() insteadDoes server require TLS encryption for authentication?
-
ssl
@Deprecated protected boolean ssl
Deprecated.since 1.3, use setSSLOnConnect() insteadDoes the current transport use SSL/TLS encryption upon connection?
-
socketTimeout
@Deprecated protected int socketTimeout
Deprecated.Socket I/O timeout value in milliseconds.
-
socketConnectionTimeout
@Deprecated protected int socketConnectionTimeout
Deprecated.Socket connection timeout value in milliseconds.
-
-
Constructor Detail
-
Email
public Email()
Constructs a new instance.
-
-
Method Detail
-
addBcc
public Email addBcc(java.lang.String email) throws EmailException
Adds a blind BCC recipient to the email. The email address will also be used as the personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.0
-
addBcc
public Email addBcc(java.lang.String... emails) throws EmailException
Adds an array of blind BCC recipients to the email. The email addresses will also be used as the personal name. The names will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
emails- A String array.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.3
-
addBcc
public Email addBcc(java.lang.String email, java.lang.String name) throws EmailException
Adds a blind BCC recipient to the email using the specified address and the specified personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.name- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.0
-
addBcc
public Email addBcc(java.lang.String email, java.lang.String name, java.lang.String charset) throws EmailException
Adds a blind BCC recipient to the email using the specified address, personal name, and charset encoding for the name.- Parameters:
email- A String.name- A String.charset- The charset to encode the name with.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.1
-
addCc
public Email addCc(java.lang.String email) throws EmailException
Adds a recipient CC to the email. The email address will also be used as the personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
-
addCc
public Email addCc(java.lang.String... emails) throws EmailException
Adds an array of CC recipients to the email. The email addresses will also be used as the personal name. The names will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
emails- A String array.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.3
-
addCc
public Email addCc(java.lang.String email, java.lang.String name) throws EmailException
Adds a recipient CC to the email using the specified address and the specified personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.name- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
-
addCc
public Email addCc(java.lang.String email, java.lang.String name, java.lang.String charset) throws EmailException
Adds a recipient CC to the email using the specified address, personal name, and charset encoding for the name.- Parameters:
email- A String.name- A String.charset- The charset to encode the name with.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address or charset.- Since:
- 1.1
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)
Adds a header ( name, value ) to the headers Map.- Parameters:
name- A String with the name.value- A String with the value.- Throws:
java.lang.IllegalArgumentException- if eithernameorvalueis null or empty- Since:
- 1.0
-
addReplyTo
public Email addReplyTo(java.lang.String email) throws EmailException
Adds a reply to address to the email. The email address will also be used as the personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.0
-
addReplyTo
public Email addReplyTo(java.lang.String email, java.lang.String name) throws EmailException
Adds a reply to address to the email using the specified address and the specified personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.name- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.0
-
addReplyTo
public Email addReplyTo(java.lang.String email, java.lang.String name, java.lang.String charset) throws EmailException
Adds a reply to address to the email using the specified address, personal name, and charset encoding for the name.- Parameters:
email- A String.name- A String.charset- The charset to encode the name with.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address or charset.- Since:
- 1.1
-
addTo
public Email addTo(java.lang.String email) throws EmailException
Adds a recipient TO to the email. The email address will also be used as the personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
-
addTo
public Email addTo(java.lang.String... emails) throws EmailException
Adds a list of TO recipients to the email. The email addresses will also be used as the personal names. The names will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
emails- A String array.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.3
-
addTo
public Email addTo(java.lang.String email, java.lang.String name) throws EmailException
Adds a recipient TO to the email using the specified address and the specified personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.name- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
-
addTo
public Email addTo(java.lang.String email, java.lang.String name, java.lang.String charset) throws EmailException
Adds a recipient TO to the email using the specified address, personal name, and charset encoding for the name.- Parameters:
email- A String.name- A String.charset- The charset to encode the name with.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address or charset.- Since:
- 1.1
-
buildMimeMessage
public void buildMimeMessage() throws EmailException
Builds the MimeMessage. Please note that a user rarely calls this method directly and only if he/she is interested in the sending the underlying MimeMessage without commons-email.- Throws:
java.lang.IllegalStateException- if the MimeMessage was already builtEmailException- if there was an error.- Since:
- 1.0
-
createMimeMessage
protected javax.mail.internet.MimeMessage createMimeMessage(javax.mail.Session aSession)
Creates a customized MimeMessage which can be implemented by a derived class, e.g. to set the message id.- Parameters:
aSession- mail session to be used- Returns:
- the newly created message
-
getAuthenticator
public javax.mail.Authenticator getAuthenticator()
Gets the authenticator.- Returns:
- the authenticator.
- Since:
- 1.6.0
-
getBccAddresses
public java.util.List<javax.mail.internet.InternetAddress> getBccAddresses()
Gets the list of "Bcc" addresses.- Returns:
- List addresses
-
getBounceAddress
public java.lang.String getBounceAddress()
Gets the "bounce address" of this email.- Returns:
- the bounce address as string
- Since:
- 1.4
-
getCcAddresses
public java.util.List<javax.mail.internet.InternetAddress> getCcAddresses()
Gets the list of "CC" addresses.- Returns:
- List addresses
-
getCharsetName
public java.lang.String getCharsetName()
Gets the Charset.- Returns:
- the Charset.
- Since:
- 1.6.0
-
getContent
public java.lang.Object getContent()
Gets the content.- Returns:
- the content.
- Since:
- 1.6.0
-
getContentType
public java.lang.String getContentType()
Gets the content type.- Returns:
- the content type.
- Since:
- 1.6.0
-
getEmailBody
public javax.mail.internet.MimeMultipart getEmailBody()
Gets the email body.- Returns:
- the email body.
- Since:
- 1.6.0
-
getFromAddress
public javax.mail.internet.InternetAddress getFromAddress()
Gets the sender of the email.- Returns:
- from address
-
getHeader
public java.lang.String getHeader(java.lang.String header)
Gets the specified header.- Parameters:
header- A string with the header.- Returns:
- The value of the header, or null if no such header.
- Since:
- 1.5
-
getHeaders
public java.util.Map<java.lang.String,java.lang.String> getHeaders()
Gets all headers on an Email.- Returns:
- a Map of all headers.
- Since:
- 1.5
-
getHostName
public java.lang.String getHostName()
Gets the host name of the SMTP server,- Returns:
- host name
-
getMailSession
public javax.mail.Session getMailSession() throws EmailException
Gets the mail session used when sending this Email, creating the Session if necessary. When a mail session is already initialized setting the session related properties will cause an IllegalStateException.- Returns:
- A Session.
- Throws:
EmailException- if the host name was not set- Since:
- 1.0
-
getMessage
public javax.mail.internet.MimeMessage getMessage()
Gets the message.- Returns:
- the message.
- Since:
- 1.6.0
-
getMimeMessage
public javax.mail.internet.MimeMessage getMimeMessage()
Gets the internal MimeMessage. Please note that the MimeMessage is built by the buildMimeMessage() method.- Returns:
- the MimeMessage
-
getPopHost
public java.lang.String getPopHost()
Gets the POP3 host.- Returns:
- the POP3 host.
- Since:
- 1.6.0
-
getPopPassword
public java.lang.String getPopPassword()
Gets the POP3 password.- Returns:
- the POP3 password.
- Since:
- 1.6.0
-
getPopUserName
public java.lang.String getPopUserName()
Gets the POP3 user name.- Returns:
- the POP3 user name.
- Since:
- 1.6.0
-
getReplyToAddresses
public java.util.List<javax.mail.internet.InternetAddress> getReplyToAddresses()
Gets the list of "Reply-To" addresses.- Returns:
- List addresses
-
getSentDate
public java.util.Date getSentDate()
Gets the sent date for the email.- Returns:
- date to be used as the sent date for the email
- Since:
- 1.0
-
getSmtpPort
public java.lang.String getSmtpPort()
Gets the listening port of the SMTP server.- Returns:
- SMTP port
-
getSocketConnectionTimeout
public int getSocketConnectionTimeout()
Gets the socket connection timeout value in milliseconds.- Returns:
- the timeout in milliseconds.
- Since:
- 1.2
-
getSocketTimeout
public int getSocketTimeout()
Gets the socket I/O timeout value in milliseconds.- Returns:
- the socket I/O timeout
- Since:
- 1.2
-
getSslSmtpPort
public java.lang.String getSslSmtpPort()
Gets the current SSL port used by the SMTP transport.- Returns:
- the current SSL port used by the SMTP transport
-
getSubject
public java.lang.String getSubject()
Gets the subject of the email.- Returns:
- email subject
-
getToAddresses
public java.util.List<javax.mail.internet.InternetAddress> getToAddresses()
Gets the list of "To" addresses.- Returns:
- List addresses
-
isDebug
public boolean isDebug()
Tests whether debug is on.- Returns:
- whether debug is on.
- Since:
- 1.6.0
-
isPopBeforeSmtp
public boolean isPopBeforeSmtp()
Tests whether to use POP3 before SMTP, and if so the settings.- Returns:
- whether to use POP3 before SMTP, and if so the settings.
- Since:
- 1.6.0
-
isSendPartial
public boolean isSendPartial()
Tests whether partial sending of email is enabled.- Returns:
- true if sending partial email is enabled.
- Since:
- 1.3.2
-
isSSL
@Deprecated public boolean isSSL()
Deprecated.since 1.3, useisSSLOnConnect()instead.Tests whether SSL/TLS encryption for the transport is currently enabled (SMTPS/POPS). See EMAIL-105 for reason of deprecation.- Returns:
- true if SSL enabled for the transport.
-
isSSLCheckServerIdentity
public boolean isSSLCheckServerIdentity()
Tests whether the server identity checked as specified by RFC 2595- Returns:
- true if the server identity is checked.
- Since:
- 1.3
-
isSSLOnConnect
public boolean isSSLOnConnect()
Tests whether SSL/TLS encryption for the transport is currently enabled (SMTPS/POPS).- Returns:
- true if SSL enabled for the transport.
- Since:
- 1.3
-
isStartTLSEnabled
public boolean isStartTLSEnabled()
Tests whether the client is configured to try to enable STARTTLS.- Returns:
- true if using STARTTLS for authentication, false otherwise.
- Since:
- 1.3
-
isStartTLSRequired
public boolean isStartTLSRequired()
Tests whether the client is configured to require STARTTLS.- Returns:
- true if using STARTTLS for authentication, false otherwise.
- Since:
- 1.3
-
isTLS
@Deprecated public boolean isTLS()
Deprecated.since 1.3, useisStartTLSEnabled()instead.Tests whether the client is configured to try to enable STARTTLS. See EMAIL-105 for reason of deprecation.- Returns:
- true if using STARTTLS for authentication, false otherwise.
- Since:
- 1.1
-
send
public java.lang.String send() throws EmailException
Sends the email. Internally we build a MimeMessage which is afterwards sent to the SMTP server.- Returns:
- the message id of the underlying MimeMessage
- Throws:
java.lang.IllegalStateException- if the MimeMessage was already built, that is,buildMimeMessage()was already calledEmailException- the sending failed
-
sendMimeMessage
public java.lang.String sendMimeMessage() throws EmailException
Sends the previously created MimeMessage to the SMTP server.- Returns:
- the message id of the underlying MimeMessage
- Throws:
java.lang.IllegalArgumentException- if the MimeMessage has not been createdEmailException- the sending failed
-
setAuthentication
public void setAuthentication(java.lang.String userName, java.lang.String password)
Sets the userName and password if authentication is needed. If this method is not used, no authentication will be performed.This method will create a new instance of
DefaultAuthenticatorusing the supplied parameters.- Parameters:
userName- User name for the SMTP serverpassword- password for the SMTP server- Since:
- 1.0
- See Also:
DefaultAuthenticator,setAuthenticator(javax.mail.Authenticator)
-
setAuthenticator
public void setAuthenticator(javax.mail.Authenticator authenticator)
Sets theAuthenticatorto be used when authentication is requested from the mail server.This method should be used when your outgoing mail server requires authentication. Your mail server must also support RFC2554.
- Parameters:
authenticator- theAuthenticatorobject.- Since:
- 1.0
- See Also:
Authenticator
-
setBcc
public Email setBcc(java.util.Collection<javax.mail.internet.InternetAddress> collection) throws EmailException
Sets a list of "BCC" addresses. All elements in the specifiedCollectionare expected to be of typejava.mail.internet.InternetAddress.- Parameters:
collection- collection ofInternetAddressobjects- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.0
- See Also:
InternetAddress
-
setBounceAddress
public Email setBounceAddress(java.lang.String email)
Sets the "bounce address" - the address to which undeliverable messages will be returned. If this value is never set, then the message will be sent to the address specified with the System property "mail.smtp.from", or if that value is not set, then to the "from" address.- Parameters:
email- A String.- Returns:
- An Email.
- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.0
-
setCc
public Email setCc(java.util.Collection<javax.mail.internet.InternetAddress> collection) throws EmailException
Sets a list of "CC" addresses. All elements in the specifiedCollectionare expected to be of typejava.mail.internet.InternetAddress.- Parameters:
collection- collection ofInternetAddressobjects.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
- See Also:
InternetAddress
-
setCharset
public void setCharset(java.lang.String charset)
Sets the charset of the message. Please note that you should set the charset before adding the message content.- Parameters:
charset- A String.- Throws:
java.nio.charset.IllegalCharsetNameException- if the charset name is invalidjava.nio.charset.UnsupportedCharsetException- if no support for the named charset exists in the current JVM- Since:
- 1.0
-
setContent
public void setContent(javax.mail.internet.MimeMultipart mimeMultipart)
Sets the emailBody to a MimeMultiPart- Parameters:
mimeMultipart- aMimeMultipart- Since:
- 1.0
-
setContent
public Email setContent(java.lang.Object content)
Sets the content.- Parameters:
content- the content.- Returns:
- this.
- Since:
- 1.6.0
-
setContent
public void setContent(java.lang.Object content, java.lang.String contentType)
Sets the content and contentType.- Parameters:
content- content.contentType- content type.- Since:
- 1.0
-
setContentType
public Email setContentType(java.lang.String contentType)
Sets the content type.- Parameters:
contentType- the content type.- Returns:
- this.
- Since:
- 1.6.0
-
setDebug
public void setDebug(boolean debug)
Sets the display of debug information.- Parameters:
debug- A boolean.- Since:
- 1.0
-
setFrom
public Email setFrom(java.lang.String email) throws EmailException
Sets the FROM field of the email to use the specified address. The email address will also be used as the personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
-
setFrom
public Email setFrom(java.lang.String email, java.lang.String name) throws EmailException
Sets the FROM field of the email to use the specified address and the specified personal name. The name will be encoded by the charset ofsetCharset(String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.- Parameters:
email- A String.name- A String.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
-
setFrom
public Email setFrom(java.lang.String email, java.lang.String name, java.lang.String charset) throws EmailException
Sets the FROM field of the email to use the specified address, personal name, and charset encoding for the name.- Parameters:
email- A String.name- A String.charset- The charset to encode the name with.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address or charset.- Since:
- 1.1
-
setFromAddress
public Email setFromAddress(javax.mail.internet.InternetAddress fromAddress)
Sets the From address.- Parameters:
fromAddress- the From address.- Returns:
- this.
- Since:
- 1.6.0
-
setHeaders
public void setHeaders(java.util.Map<java.lang.String,java.lang.String> map)
Sets the mail headers. Example: X-Mailer: Sendmail, X-Priority: 1( highest ) or 2( high ) 3( normal ) 4( low ) and 5( lowest ) Disposition-Notification-To: user@domain.net- Parameters:
map- A Map.- Throws:
java.lang.IllegalArgumentException- if either of the provided header / value is null or empty- Since:
- 1.0
-
setHostName
public void setHostName(java.lang.String hostName)
Sets the hostname of the outgoing mail server.- Parameters:
hostName- aHostName- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.0
-
setMailSession
public void setMailSession(javax.mail.Session session)
Sets a mail Session object to use. Please note that passing a user name and password (in the case of mail authentication) will create a new mail session with a DefaultAuthenticator. This is a convenience but might come unexpected. If mail authentication is used but NO user name and password is supplied the implementation assumes that you have set a authenticator and will use the existing mail session (as expected).- Parameters:
session- mail session to be used- Throws:
java.lang.NullPointerException- ifaSessionisnull- Since:
- 1.0
-
setMailSessionFromJNDI
public void setMailSessionFromJNDI(java.lang.String jndiName) throws javax.naming.NamingException
Sets a mail Session object from a JNDI directory.- Parameters:
jndiName- name of JNDI resource (javax.mail.Session type), resource if searched in java:comp/env if name does not start with "java:"- Throws:
java.lang.IllegalArgumentException- if the JNDI name is null or emptyjavax.naming.NamingException- if the resource cannot be retrieved from JNDI directory- Since:
- 1.1
-
setMessage
public void setMessage(javax.mail.internet.MimeMessage message)
Sets the MIME message.- Parameters:
message- the MIME message.
-
setMsg
public abstract Email setMsg(java.lang.String msg) throws EmailException
Sets the content of the mail. It should be overridden by the subclasses.- Parameters:
msg- A String.- Returns:
- An Email.
- Throws:
EmailException- generic exception.- Since:
- 1.0
-
setPopBeforeSmtp
public Email setPopBeforeSmtp(boolean popBeforeSmtp)
Sets whether to use POP3 before SMTP, and if so the settings.- Parameters:
popBeforeSmtp- whether to use POP3 before SMTP, and if so the settings.- Returns:
- this.
- Since:
- 1.6.0
-
setPopBeforeSmtp
public void setPopBeforeSmtp(boolean popBeforeSmtp, java.lang.String popHost, java.lang.String popUserName, java.lang.String popPassword)
Sets details regarding "POP3 before SMTP" authentication.- Parameters:
popBeforeSmtp- Whether or not to log into POP3 server before sending mail.popHost- The POP3 host to use.popUserName- The POP3 user name.popPassword- The POP3 password.- Since:
- 1.0
-
setPopHost
public Email setPopHost(java.lang.String popHost)
Sets the POP3 host.- Parameters:
popHost- The POP3 host.- Returns:
- this.
- Since:
- 1.6.0
-
setPopPassword
public Email setPopPassword(java.lang.String popPassword)
Sets the POP3 password.- Parameters:
popPassword- the POP3 password.- Returns:
- this.
- Since:
- 1.6.0
-
setPopUsername
public Email setPopUsername(java.lang.String popUserName)
Sets the POP3 user name.- Parameters:
popUserName- the POP3 user name.- Returns:
- this.
- Since:
- 1.6.0
-
setReplyTo
public Email setReplyTo(java.util.Collection<javax.mail.internet.InternetAddress> collection) throws EmailException
Sets a list of reply to addresses. All elements in the specifiedCollectionare expected to be of typejava.mail.internet.InternetAddress.- Parameters:
collection- collection ofInternetAddressobjects- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address- Since:
- 1.1
- See Also:
InternetAddress
-
setSendPartial
public Email setSendPartial(boolean sendPartial)
Sets whether the email is partially send in case of invalid addresses.In case the mail server rejects an address as invalid, the call to
send()may throw aSendFailedException, even if partial send mode is enabled (emails to valid addresses will be transmitted). In case the email server does not reject invalid addresses immediately, but return a bounce message, no exception will be thrown by thesend()method.- Parameters:
sendPartial- whether to enable partial send mode- Returns:
- An Email.
- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.3.2
-
setSentDate
public void setSentDate(java.util.Date date)
Sets the sent date for the email. The sent date will default to the current date if not explicitly set.- Parameters:
date- Date to use as the sent date on the email- Since:
- 1.0
-
setSmtpPort
public void setSmtpPort(int portNumber)
Sets the non-SSL port number of the outgoing mail server.- Parameters:
portNumber- aPortNumber- Throws:
java.lang.IllegalArgumentException- if the port number is < 1java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.0
- See Also:
setSslSmtpPort(String)
-
setSocketConnectionTimeout
public void setSocketConnectionTimeout(java.time.Duration socketConnectionTimeout)
Sets the socket connection timeout value in milliseconds. Default is a 60 second timeout.- Parameters:
socketConnectionTimeout- the connection timeout- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.6.0
-
setSocketConnectionTimeout
@Deprecated public void setSocketConnectionTimeout(int socketConnectionTimeout)
Deprecated.Sets the socket connection timeout value in milliseconds. Default is a 60 second timeout.- Parameters:
socketConnectionTimeout- the connection timeout- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.2
-
setSocketTimeout
public void setSocketTimeout(java.time.Duration socketTimeout)
Sets the socket I/O timeout value in milliseconds. Default is 60 second timeout.- Parameters:
socketTimeout- the socket I/O timeout- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.6.0
-
setSocketTimeout
@Deprecated public void setSocketTimeout(int socketTimeout)
Deprecated.Sets the socket I/O timeout value in milliseconds. Default is 60 second timeout.- Parameters:
socketTimeout- the socket I/O timeout- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.2
-
setSSL
@Deprecated public void setSSL(boolean ssl)
Deprecated.since 1.3, usesetSSLOnConnect(boolean)instead.Sets whether SSL/TLS encryption should be enabled for the SMTP transport upon connection (SMTPS/POPS). See EMAIL-105 for reason of deprecation.- Parameters:
ssl- whether to enable the SSL transport
-
setSSLCheckServerIdentity
public Email setSSLCheckServerIdentity(boolean sslCheckServerIdentity)
Sets whether the server identity is checked as specified by RFC 2595- Parameters:
sslCheckServerIdentity- whether to enable server identity check- Returns:
- An Email.
- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.3
-
setSSLOnConnect
public Email setSSLOnConnect(boolean ssl)
Sets whether SSL/TLS encryption should be enabled for the SMTP transport upon connection (SMTPS/POPS). Takes precedence oversetStartTLSRequired(boolean)Defaults to
sslSmtpPort; can be overridden by usingsetSslSmtpPort(String)- Parameters:
ssl- whether to enable the SSL transport- Returns:
- An Email.
- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.3
-
setSslSmtpPort
public void setSslSmtpPort(java.lang.String sslSmtpPort)
Sets the SSL port to use for the SMTP transport. Defaults to the standard port, 465.- Parameters:
sslSmtpPort- the SSL port to use for the SMTP transport- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- See Also:
setSmtpPort(int)
-
setStartTLSEnabled
public Email setStartTLSEnabled(boolean startTlsEnabled)
Sets or disable the STARTTLS encryption.- Parameters:
startTlsEnabled- true if STARTTLS requested, false otherwise- Returns:
- An Email.
- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.3
-
setStartTLSRequired
public Email setStartTLSRequired(boolean startTlsRequired)
Sets or disable the required STARTTLS encryption.Defaults to
smtpPort; can be overridden by usingsetSmtpPort(int)- Parameters:
startTlsRequired- true if STARTTLS requested, false otherwise- Returns:
- An Email.
- Throws:
java.lang.IllegalStateException- if the mail session is already initialized- Since:
- 1.3
-
setSubject
public Email setSubject(java.lang.String aSubject)
Sets the email subject. Replaces end-of-line characters with spaces.- Parameters:
aSubject- A String.- Returns:
- An Email.
- Since:
- 1.0
-
setTLS
@Deprecated public void setTLS(boolean withTLS)
Deprecated.since 1.3, usesetStartTLSEnabled(boolean)instead.Sets or disable the STARTTLS encryption. Please see EMAIL-105 for the reasons of deprecation.- Parameters:
withTLS- true if STARTTLS requested, false otherwise- Since:
- 1.1
-
setTo
public Email setTo(java.util.Collection<javax.mail.internet.InternetAddress> collection) throws EmailException
Sets a list of "TO" addresses. All elements in the specifiedCollectionare expected to be of typejava.mail.internet.InternetAddress.- Parameters:
collection- collection ofInternetAddressobjects.- Returns:
- An Email.
- Throws:
EmailException- Indicates an invalid email address.- Since:
- 1.0
- See Also:
InternetAddress
-
toInternetAddressArray
protected javax.mail.internet.InternetAddress[] toInternetAddressArray(java.util.List<javax.mail.internet.InternetAddress> list)
Converts to copy List of known InternetAddress objects into an array.- Parameters:
list- A List.- Returns:
- An InternetAddress[].
- Since:
- 1.0
-
updateContentType
public void updateContentType(java.lang.String contentType)
Updates the contentType.- Parameters:
contentType- aContentType- Since:
- 1.2
-
-