Package org.apache.commons.mail
Class MultiPartEmail
- java.lang.Object
-
- org.apache.commons.mail.Email
-
- org.apache.commons.mail.MultiPartEmail
-
- Direct Known Subclasses:
HtmlEmail
public class MultiPartEmail extends Email
A multipart email.This class is used to send multi-part internet email like messages with attachments.
To create a multi-part email, call the default constructor and then you can call setMsg() to set the message and call the different attach() methods.
- Since:
- 1.0
-
-
Field Summary
-
Fields inherited from class org.apache.commons.mail.Email
ATTACHMENTS, authenticator, bccList, bounceAddress, ccList, charset, content, CONTENT_TYPE, contentType, debug, EMAIL_BODY, EMAIL_SUBJECT, emailBody, FILE_SERVER, fromAddress, headers, hostName, ISO_8859_1, KOI8_R, MAIL_DEBUG, MAIL_HOST, MAIL_PORT, MAIL_SMTP_AUTH, MAIL_SMTP_CONNECTIONTIMEOUT, MAIL_SMTP_FROM, MAIL_SMTP_PASSWORD, MAIL_SMTP_SOCKET_FACTORY_CLASS, MAIL_SMTP_SOCKET_FACTORY_FALLBACK, MAIL_SMTP_SOCKET_FACTORY_PORT, MAIL_SMTP_TIMEOUT, MAIL_SMTP_USER, MAIL_TRANSPORT_PROTOCOL, MAIL_TRANSPORT_TLS, message, popBeforeSmtp, popHost, popPassword, popUsername, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, sentDate, SMTP, smtpPort, socketConnectionTimeout, socketTimeout, ssl, sslSmtpPort, subject, TEXT_HTML, TEXT_PLAIN, tls, toList, US_ASCII
-
-
Constructor Summary
Constructors Constructor Description MultiPartEmail()Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EmailaddPart(java.lang.String partContent, java.lang.String partContentType)Adds a new part to the email.EmailaddPart(javax.mail.internet.MimeMultipart multipart)Adds a new part to the email.EmailaddPart(javax.mail.internet.MimeMultipart multipart, int index)Adds a new part to the email.MultiPartEmailattach(java.io.File file)Attaches a file.MultiPartEmailattach(java.net.URL url, java.lang.String name, java.lang.String description)Attaches a file located by its URL.MultiPartEmailattach(java.net.URL url, java.lang.String name, java.lang.String description, java.lang.String disposition)Attaches a file located by its URL.MultiPartEmailattach(java.nio.file.Path file, java.nio.file.OpenOption... options)Attaches a path.MultiPartEmailattach(javax.activation.DataSource dataSource, java.lang.String name, java.lang.String description)Attaches a file specified as a DataSource interface.MultiPartEmailattach(javax.activation.DataSource dataSource, java.lang.String name, java.lang.String description, java.lang.String disposition)Attaches a file specified as a DataSource interface.MultiPartEmailattach(EmailAttachment attachment)Attaches an EmailAttachment.voidbuildMimeMessage()Builds the MimeMessage.protected javax.mail.BodyPartcreateBodyPart()Creates a body part object.protected javax.mail.internet.MimeMultipartcreateMimeMultipart()Creates a mime multipart object.protected javax.mail.internet.MimeMultipartgetContainer()Gets the message container.protected javax.mail.BodyPartgetPrimaryBodyPart()Gets first body part of the message.java.lang.StringgetSubType()Gets the MIME subtype of the email.protected voidinit()Initialize the multipart email.booleanisBoolHasAttachments()Tests whether there are attachments.protected booleanisInitialized()Tests if this object is initialized.voidsetBoolHasAttachments(boolean hasAttachments)Sets whether there are attachments.protected voidsetInitialized(boolean initialized)Sets the initialized status of this object.EmailsetMsg(java.lang.String msg)Sets the message of the email.voidsetSubType(java.lang.String subType)Sets the MIME subtype of the email.-
Methods inherited from class org.apache.commons.mail.Email
addBcc, addBcc, addBcc, addBcc, addCc, addCc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addReplyTo, addTo, addTo, addTo, addTo, createMimeMessage, getAuthenticator, getBccAddresses, getBounceAddress, getCcAddresses, getCharsetName, getContent, getContentType, getEmailBody, getFromAddress, getHeader, getHeaders, getHostName, getMailSession, getMessage, getMimeMessage, getPopHost, getPopPassword, getPopUserName, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isDebug, isPopBeforeSmtp, isSendPartial, isSSL, isSSLCheckServerIdentity, isSSLOnConnect, isStartTLSEnabled, isStartTLSRequired, isTLS, send, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setContent, setContentType, setDebug, setFrom, setFrom, setFrom, setFromAddress, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setMessage, setPopBeforeSmtp, setPopBeforeSmtp, setPopHost, setPopPassword, setPopUsername, setReplyTo, setSendPartial, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketConnectionTimeout, setSocketTimeout, setSocketTimeout, setSSL, setSSLCheckServerIdentity, setSSLOnConnect, setSslSmtpPort, setStartTLSEnabled, setStartTLSRequired, setSubject, setTLS, setTo, toInternetAddressArray, updateContentType
-
-
-
-
Constructor Detail
-
MultiPartEmail
public MultiPartEmail()
Constructs a new instance.
-
-
Method Detail
-
addPart
public Email addPart(javax.mail.internet.MimeMultipart multipart) throws EmailException
Adds a new part to the email.- Parameters:
multipart- The MimeMultipart.- Returns:
- An Email.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
addPart
public Email addPart(javax.mail.internet.MimeMultipart multipart, int index) throws EmailException
Adds a new part to the email.- Parameters:
multipart- The part to add.index- The index to add at.- Returns:
- The email.
- Throws:
EmailException- An error occurred while adding the part.- Since:
- 1.0
-
addPart
public Email addPart(java.lang.String partContent, java.lang.String partContentType) throws EmailException
Adds a new part to the email.- Parameters:
partContent- The content.partContentType- The content type.- Returns:
- An Email.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
attach
public MultiPartEmail attach(javax.activation.DataSource dataSource, java.lang.String name, java.lang.String description) throws EmailException
Attaches a file specified as a DataSource interface.- Parameters:
dataSource- A DataSource interface for the file.name- The name field for the attachment.description- A description for the attachment.- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
attach
public MultiPartEmail attach(javax.activation.DataSource dataSource, java.lang.String name, java.lang.String description, java.lang.String disposition) throws EmailException
Attaches a file specified as a DataSource interface.- Parameters:
dataSource- A DataSource interface for the file.name- The name field for the attachment.description- A description for the attachment.disposition- Either mixed or inline.- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
attach
public MultiPartEmail attach(EmailAttachment attachment) throws EmailException
Attaches an EmailAttachment.- Parameters:
attachment- An EmailAttachment.- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
attach
public MultiPartEmail attach(java.io.File file) throws EmailException
Attaches a file.- Parameters:
file- A file attachment- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.3
-
attach
public MultiPartEmail attach(java.nio.file.Path file, java.nio.file.OpenOption... options) throws EmailException
Attaches a path.- Parameters:
file- A file attachment.options- options for opening file streams.- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.6.0
-
attach
public MultiPartEmail attach(java.net.URL url, java.lang.String name, java.lang.String description) throws EmailException
Attaches a file located by its URL. The disposition of the file is set to mixed.- Parameters:
url- The URL of the file (may be any valid URL).name- The name field for the attachment.description- A description for the attachment.- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
attach
public MultiPartEmail attach(java.net.URL url, java.lang.String name, java.lang.String description, java.lang.String disposition) throws EmailException
Attaches a file located by its URL.- Parameters:
url- The URL of the file (may be any valid URL).name- The name field for the attachment.description- A description for the attachment.disposition- Either mixed or inline.- Returns:
- A MultiPartEmail.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
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.- Overrides:
buildMimeMessagein classEmail- Throws:
EmailException- if there was an error.- Since:
- 1.0
-
createBodyPart
protected javax.mail.BodyPart createBodyPart()
Creates a body part object. Can be overridden if you don't want to create a BodyPart.- Returns:
- the created body part
-
createMimeMultipart
protected javax.mail.internet.MimeMultipart createMimeMultipart()
Creates a mime multipart object.- Returns:
- the created mime part
-
getContainer
protected javax.mail.internet.MimeMultipart getContainer()
Gets the message container.- Returns:
- The message container.
- Since:
- 1.0
-
getPrimaryBodyPart
protected javax.mail.BodyPart getPrimaryBodyPart() throws javax.mail.MessagingException
Gets first body part of the message.- Returns:
- The primary body part.
- Throws:
javax.mail.MessagingException- An error occurred while getting the primary body part.- Since:
- 1.0
-
getSubType
public java.lang.String getSubType()
Gets the MIME subtype of the email.- Returns:
- MIME subtype of the email
- Since:
- 1.0
-
init
protected void init()
Initialize the multipart email.- Since:
- 1.0
-
isBoolHasAttachments
public boolean isBoolHasAttachments()
Tests whether there are attachments.- Returns:
- true if there are attachments
- Since:
- 1.0
-
isInitialized
protected boolean isInitialized()
Tests if this object is initialized.- Returns:
- true if initialized
-
setBoolHasAttachments
public void setBoolHasAttachments(boolean hasAttachments)
Sets whether there are attachments.- Parameters:
hasAttachments- the attachments flag- Since:
- 1.0
-
setInitialized
protected void setInitialized(boolean initialized)
Sets the initialized status of this object.- Parameters:
initialized- the initialized status flag
-
setMsg
public Email setMsg(java.lang.String msg) throws EmailException
Sets the message of the email.- Specified by:
setMsgin classEmail- Parameters:
msg- A String.- Returns:
- An Email.
- Throws:
EmailException- see javax.mail.internet.MimeBodyPart for definitions- Since:
- 1.0
-
setSubType
public void setSubType(java.lang.String subType)
Sets the MIME subtype of the email.- Parameters:
subType- MIME subtype of the email- Since:
- 1.0
-
-