Class Email
- Direct Known Subclasses:
MultiPartEmail
,SimpleEmail
Subclasses are responsible for setting the message body.
- Since:
- 1.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds a blind BCC recipient to the email.Adds an array of blind BCC recipients to the email.Adds a blind BCC recipient to the email using the specified address and the specified personal name.Adds a blind BCC recipient to the email using the specified address, personal name, and charset encoding for the name.Adds a recipient CC to the email.Adds an array of CC recipients to the email.Adds a recipient CC to the email using the specified address and the specified personal name.Adds a recipient CC to the email using the specified address, personal name, and charset encoding for the name.void
Adds a header ( name, value ) to the headers Map.addReplyTo
(String email) Adds a reply to address to the email.addReplyTo
(String email, String name) Adds a reply to address to the email using the specified address and the specified personal name.addReplyTo
(String email, String name, String charset) Adds a reply to address to the email using the specified address, personal name, and charset encoding for the name.Adds a recipient TO to the email.Adds a list of TO recipients to the email.Adds a recipient TO to the email using the specified address and the specified personal name.Adds a recipient TO to the email using the specified address, personal name, and charset encoding for the name.void
Builds the MimeMessage.protected MimeMessage
createMimeMessage
(Session aSession) Creates a customized MimeMessage which can be implemented by a derived class, e.g.Gets the authenticator.Gets the list of "Bcc" addresses.Gets the "bounce address" of this email.Gets the list of "CC" addresses.Gets the Charset.Gets the content.Gets the content type.Gets the email body.Gets the sender of the email.Gets the specified header.Gets all headers on an Email.Gets the host name of the SMTP server,Gets the mail session used when sending this Email, creating the Session if necessary.Gets the message.Gets the internal MimeMessage.Gets the POP3 host.Gets the POP3 password.Gets the POP3 user name.Gets the list of "Reply-To" addresses.Gets the sent date for the email.Gets the listening port of the SMTP server.int
Gets the socket connection timeout value in milliseconds.int
Gets the socket I/O timeout value in milliseconds.Gets the current SSL port used by the SMTP transport.Gets the subject of the email.Gets the list of "To" addresses.boolean
isDebug()
Tests whether debug is on.boolean
Tests whether to use POP3 before SMTP, and if so the settings.boolean
Tests whether partial sending of email is enabled.boolean
Tests whether the server identity checked as specified by RFC 2595boolean
Tests whether SSL/TLS encryption for the transport is currently enabled (SMTPS/POPS).boolean
Tests whether the client is configured to try to enable STARTTLS.boolean
Tests whether the client is configured to require STARTTLS.send()
Sends the email.Sends the previously created MimeMessage to the SMTP server.void
setAuthentication
(String userName, String password) Sets the userName and password if authentication is needed.void
setAuthenticator
(Authenticator authenticator) Sets theAuthenticator
to be used when authentication is requested from the mail server.setBcc
(Collection<InternetAddress> collection) Sets a list of "BCC" addresses.setBounceAddress
(String email) Sets the "bounce address" - the address to which undeliverable messages will be returned.setCc
(Collection<InternetAddress> collection) Sets a list of "CC" addresses.void
setCharset
(String charset) Sets the charset of the message.setContent
(Object content) Sets the content.void
setContent
(Object content, String contentType) Sets the content and contentType.void
setContent
(MimeMultipart mimeMultipart) Sets the emailBody to a MimeMultiPartsetContentType
(String contentType) Sets the content type.void
setDebug
(boolean debug) Sets the display of debug information.Sets the FROM field of the email to use the specified address.Sets the FROM field of the email to use the specified address and the specified personal name.Sets the FROM field of the email to use the specified address, personal name, and charset encoding for the name.setFromAddress
(InternetAddress fromAddress) Sets the From address.void
setHeaders
(Map<String, String> map) Sets the mail headers.void
setHostName
(String hostName) Sets the hostname of the outgoing mail server.void
setMailSession
(Session session) Sets a mail Session object to use.void
setMailSessionFromJNDI
(String jndiName) Sets a mail Session object from a JNDI directory.void
setMessage
(MimeMessage message) Sets the MIME message.abstract Email
Sets the content of the mail.setPopBeforeSmtp
(boolean popBeforeSmtp) Sets whether to use POP3 before SMTP, and if so the settings.void
setPopBeforeSmtp
(boolean popBeforeSmtp, String popHost, String popUserName, String popPassword) Sets details regarding "POP3 before SMTP" authentication.setPopHost
(String popHost) Sets the POP3 host.setPopPassword
(String popPassword) Sets the POP3 password.setPopUsername
(String popUserName) Sets the POP3 user name.setReplyTo
(Collection<InternetAddress> collection) Sets a list of reply to addresses.setSendPartial
(boolean sendPartial) Sets whether the email is partially send in case of invalid addresses.void
setSentDate
(Date date) Sets the sent date for the email.void
setSmtpPort
(int portNumber) Sets the non-SSL port number of the outgoing mail server.void
setSocketConnectionTimeout
(Duration socketConnectionTimeout) Sets the socket connection timeout value in milliseconds.void
setSocketTimeout
(Duration socketTimeout) Sets the socket I/O timeout value in milliseconds.setSSLCheckServerIdentity
(boolean sslCheckServerIdentity) Sets whether the server identity is checked as specified by RFC 2595setSSLOnConnect
(boolean ssl) Sets whether SSL/TLS encryption should be enabled for the SMTP transport upon connection (SMTPS/POPS).void
setSslSmtpPort
(String sslSmtpPort) Sets the SSL port to use for the SMTP transport.setStartTLSEnabled
(boolean startTlsEnabled) Sets or disable the STARTTLS encryption.setStartTLSRequired
(boolean startTlsRequired) Sets or disable the required STARTTLS encryption.setSubject
(String aSubject) Sets the email subject.setTo
(Collection<InternetAddress> collection) Sets a list of "TO" addresses.protected InternetAddress[]
Converts to copy List of known InternetAddress objects into an array.void
updateContentType
(String contentType) Updates the contentType.
-
Constructor Details
-
Email
public Email()Constructs a new instance.
-
-
Method Details
-
addBcc
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
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
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
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
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
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
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
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
Adds a header ( name, value ) to the headers Map.- Parameters:
name
- A String with the name.value
- A String with the value.- Throws:
IllegalArgumentException
- if eithername
orvalue
is null or empty- Since:
- 1.0
-
addReplyTo
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
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
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
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
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
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
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
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:
IllegalStateException
- if the MimeMessage was already builtEmailException
- if there was an error.- Since:
- 1.0
-
createMimeMessage
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
Gets the authenticator.- Returns:
- the authenticator.
- Since:
- 1.6.0
-
getBccAddresses
Gets the list of "Bcc" addresses.- Returns:
- List addresses
-
getBounceAddress
Gets the "bounce address" of this email.- Returns:
- the bounce address as string
- Since:
- 1.4
-
getCcAddresses
Gets the list of "CC" addresses.- Returns:
- List addresses
-
getCharsetName
Gets the Charset.- Returns:
- the Charset.
- Since:
- 1.6.0
-
getContent
Gets the content.- Returns:
- the content.
- Since:
- 1.6.0
-
getContentType
Gets the content type.- Returns:
- the content type.
- Since:
- 1.6.0
-
getEmailBody
Gets the email body.- Returns:
- the email body.
- Since:
- 1.6.0
-
getFromAddress
Gets the sender of the email.- Returns:
- from address
-
getHeader
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
Gets all headers on an Email.- Returns:
- a Map of all headers.
- Since:
- 1.5
-
getHostName
Gets the host name of the SMTP server,- Returns:
- host name
-
getMailSession
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
Gets the message.- Returns:
- the message.
- Since:
- 1.6.0
-
getMimeMessage
Gets the internal MimeMessage. Please note that the MimeMessage is built by the buildMimeMessage() method.- Returns:
- the MimeMessage
-
getPopHost
Gets the POP3 host.- Returns:
- the POP3 host.
- Since:
- 1.6.0
-
getPopPassword
Gets the POP3 password.- Returns:
- the POP3 password.
- Since:
- 1.6.0
-
getPopUserName
Gets the POP3 user name.- Returns:
- the POP3 user name.
- Since:
- 1.6.0
-
getReplyToAddresses
Gets the list of "Reply-To" addresses.- Returns:
- List addresses
-
getSentDate
Gets the sent date for the email.- Returns:
- date to be used as the sent date for the email
- Since:
- 1.0
-
getSmtpPort
Gets the listening port of the SMTP server.- Returns:
- SMTP port
-
getSocketConnectionTimeout
Gets the socket connection timeout value in milliseconds.- Returns:
- the timeout in milliseconds.
- Since:
- 1.2
-
getSocketTimeout
Gets the socket I/O timeout value in milliseconds.- Returns:
- the socket I/O timeout
- Since:
- 1.2
-
getSslSmtpPort
Gets the current SSL port used by the SMTP transport.- Returns:
- the current SSL port used by the SMTP transport
-
getSubject
Gets the subject of the email.- Returns:
- email subject
-
getToAddresses
Gets the list of "To" addresses.- Returns:
- List addresses
-
isDebug
Tests whether debug is on.- Returns:
- whether debug is on.
- Since:
- 1.6.0
-
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
Tests whether partial sending of email is enabled.- Returns:
- true if sending partial email is enabled.
- Since:
- 1.3.2
-
isSSLCheckServerIdentity
Tests whether the server identity checked as specified by RFC 2595- Returns:
- true if the server identity is checked.
- Since:
- 1.3
-
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
Tests whether the client is configured to try to enable STARTTLS.- Returns:
- true if using STARTTLS for authentication, false otherwise.
- Since:
- 1.3
-
isStartTLSRequired
Tests whether the client is configured to require STARTTLS.- Returns:
- true if using STARTTLS for authentication, false otherwise.
- Since:
- 1.3
-
send
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:
IllegalStateException
- if the MimeMessage was already built, that is,buildMimeMessage()
was already calledEmailException
- the sending failed
-
sendMimeMessage
Sends the previously created MimeMessage to the SMTP server.- Returns:
- the message id of the underlying MimeMessage
- Throws:
IllegalArgumentException
- if the MimeMessage has not been createdEmailException
- the sending failed
-
setAuthentication
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
DefaultAuthenticator
using the supplied parameters.- Parameters:
userName
- User name for the SMTP serverpassword
- password for the SMTP server- Since:
- 1.0
- See Also:
-
setAuthenticator
Sets theAuthenticator
to 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
- theAuthenticator
object.- Since:
- 1.0
- See Also:
-
setBcc
Sets a list of "BCC" addresses. All elements in the specifiedCollection
are expected to be of typejava.mail.internet.InternetAddress
.- Parameters:
collection
- collection ofInternetAddress
objects- Returns:
- An Email.
- Throws:
EmailException
- Indicates an invalid email address- Since:
- 1.0
- See Also:
-
setBounceAddress
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:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.0
-
setCc
Sets a list of "CC" addresses. All elements in the specifiedCollection
are expected to be of typejava.mail.internet.InternetAddress
.- Parameters:
collection
- collection ofInternetAddress
objects.- Returns:
- An Email.
- Throws:
EmailException
- Indicates an invalid email address.- Since:
- 1.0
- See Also:
-
setCharset
Sets the charset of the message. Please note that you should set the charset before adding the message content.- Parameters:
charset
- A String.- Throws:
IllegalCharsetNameException
- if the charset name is invalidUnsupportedCharsetException
- if no support for the named charset exists in the current JVM- Since:
- 1.0
-
setContent
Sets the emailBody to a MimeMultiPart- Parameters:
mimeMultipart
- aMimeMultipart- Since:
- 1.0
-
setContent
Sets the content.- Parameters:
content
- the content.- Returns:
this
instance.- Since:
- 1.6.0
-
setContent
Sets the content and contentType.- Parameters:
content
- content.contentType
- content type.- Since:
- 1.0
-
setContentType
Sets the content type.- Parameters:
contentType
- the content type.- Returns:
this
instance.- Since:
- 1.6.0
-
setDebug
Sets the display of debug information.- Parameters:
debug
- A boolean.- Since:
- 1.0
-
setFrom
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
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
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
Sets the From address.- Parameters:
fromAddress
- the From address.- Returns:
this
instance.- Since:
- 1.6.0
-
setHeaders
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:
IllegalArgumentException
- if either of the provided header / value is null or empty- Since:
- 1.0
-
setHostName
Sets the hostname of the outgoing mail server.- Parameters:
hostName
- aHostName- Throws:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.0
-
setMailSession
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:
NullPointerException
- ifaSession
isnull
- Since:
- 1.0
-
setMailSessionFromJNDI
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:
IllegalArgumentException
- if the JNDI name is null or emptyNamingException
- if the resource cannot be retrieved from JNDI directory- Since:
- 1.1
-
setMessage
Sets the MIME message.- Parameters:
message
- the MIME message.
-
setMsg
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
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
instance.- Since:
- 1.6.0
-
setPopBeforeSmtp
public void setPopBeforeSmtp(boolean popBeforeSmtp, String popHost, String popUserName, 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
Sets the POP3 host.- Parameters:
popHost
- The POP3 host.- Returns:
this
instance.- Since:
- 1.6.0
-
setPopPassword
Sets the POP3 password.- Parameters:
popPassword
- the POP3 password.- Returns:
this
instance.- Since:
- 1.6.0
-
setPopUsername
Sets the POP3 user name.- Parameters:
popUserName
- the POP3 user name.- Returns:
this
instance.- Since:
- 1.6.0
-
setReplyTo
Sets a list of reply to addresses. All elements in the specifiedCollection
are expected to be of typejava.mail.internet.InternetAddress
.- Parameters:
collection
- collection ofInternetAddress
objects- Returns:
- An Email.
- Throws:
EmailException
- Indicates an invalid email address- Since:
- 1.1
- See Also:
-
setSendPartial
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:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.3.2
-
setSentDate
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
Sets the non-SSL port number of the outgoing mail server.- Parameters:
portNumber
- aPortNumber- Throws:
IllegalArgumentException
- if the port number is < 1IllegalStateException
- if the mail session is already initialized- Since:
- 1.0
- See Also:
-
setSocketConnectionTimeout
Sets the socket connection timeout value in milliseconds. Default is a 60 second timeout.- Parameters:
socketConnectionTimeout
- the connection timeout- Throws:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.6.0
-
setSocketTimeout
Sets the socket I/O timeout value in milliseconds. Default is 60 second timeout.- Parameters:
socketTimeout
- the socket I/O timeout- Throws:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.6.0
-
setSSLCheckServerIdentity
Sets whether the server identity is checked as specified by RFC 2595- Parameters:
sslCheckServerIdentity
- whether to enable server identity check- Returns:
- An Email.
- Throws:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.3
-
setSSLOnConnect
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:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.3
-
setSslSmtpPort
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:
IllegalStateException
- if the mail session is already initialized- See Also:
-
setStartTLSEnabled
Sets or disable the STARTTLS encryption.- Parameters:
startTlsEnabled
- true if STARTTLS requested, false otherwise- Returns:
- An Email.
- Throws:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.3
-
setStartTLSRequired
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:
IllegalStateException
- if the mail session is already initialized- Since:
- 1.3
-
setSubject
Sets the email subject. Replaces end-of-line characters with spaces.- Parameters:
aSubject
- A String.- Returns:
- An Email.
- Since:
- 1.0
-
setTo
Sets a list of "TO" addresses. All elements in the specifiedCollection
are expected to be of typejava.mail.internet.InternetAddress
.- Parameters:
collection
- collection ofInternetAddress
objects.- Returns:
- An Email.
- Throws:
EmailException
- Indicates an invalid email address.- Since:
- 1.0
- See Also:
-
toInternetAddressArray
Converts to copy List of known InternetAddress objects into an array.- Parameters:
list
- A List.- Returns:
- An InternetAddress[].
- Since:
- 1.0
-
updateContentType
Updates the contentType.- Parameters:
contentType
- aContentType- Since:
- 1.2
-