Package org.apache.commons.mail2.javax
Class MultiPartEmail
java.lang.Object
org.apache.commons.mail2.javax.Email
org.apache.commons.mail2.javax.MultiPartEmail
- Direct Known Subclasses:
- HtmlEmail
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
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionAdds a new part to the email.addPart(MimeMultipart multipart) Adds a new part to the email.addPart(MimeMultipart multipart, int index) Adds a new part to the email.Attaches a file.Attaches a file located by its URL.Attaches a file located by its URL.attach(Path file, OpenOption... options) Attaches a path.attach(DataSource dataSource, String name, String description) Attaches a file specified as a DataSource interface.attach(DataSource dataSource, String name, String description, String disposition) Attaches a file specified as a DataSource interface.attach(EmailAttachment attachment) Attaches an EmailAttachment.voidBuilds the MimeMessage.protected BodyPartCreates a body part object.protected MimeMultipartCreates a mime multipart object.protected MimeMultipartGets the message container.protected BodyPartGets first body part of the message.Gets the MIME subtype of the email.protected voidinit()Initialize the multipart email.booleanTests whether there are attachments.protected booleanTests if this object is initialized.voidsetBoolHasAttachments(boolean hasAttachments) Sets whether there are attachments.protected voidsetInitialized(boolean initialized) Sets the initialized status of this object.Sets the message of the email.voidsetSubType(String subType) Sets the MIME subtype of the email.Methods inherited from class org.apache.commons.mail2.javax.EmailaddBcc, 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, isSSLCheckServerIdentity, isSSLOnConnect, isStartTLSEnabled, isStartTLSRequired, 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, setSocketTimeout, setSSLCheckServerIdentity, setSSLOnConnect, setSslSmtpPort, setStartTLSEnabled, setStartTLSRequired, setSubject, setTo, toInternetAddressArray, updateContentType
- 
Constructor Details- 
MultiPartEmailpublic MultiPartEmail()Constructs a new instance.
 
- 
- 
Method Details- 
addPartAdds 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
 
- 
addPartAdds 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
 
- 
addPartAdds 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
 
- 
attachpublic MultiPartEmail attach(DataSource dataSource, String name, 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
 
- 
attachpublic MultiPartEmail attach(DataSource dataSource, String name, String description, 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
 
- 
attachAttaches an EmailAttachment.- Parameters:
- attachment- An EmailAttachment.
- Returns:
- A MultiPartEmail.
- Throws:
- EmailException- see javax.mail.internet.MimeBodyPart for definitions
- Since:
- 1.0
 
- 
attachAttaches a file.- Parameters:
- file- A file attachment
- Returns:
- A MultiPartEmail.
- Throws:
- EmailException- see javax.mail.internet.MimeBodyPart for definitions
- Since:
- 1.3
 
- 
attachAttaches 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
 
- 
attachAttaches 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
 
- 
attachpublic MultiPartEmail attach(URL url, String name, String description, 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
 
- 
buildMimeMessageBuilds 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 class- Email
- Throws:
- EmailException- if there was an error.
- Since:
- 1.0
 
- 
createBodyPartCreates a body part object. Can be overridden if you don't want to create a BodyPart.- Returns:
- the created body part
 
- 
createMimeMultipartCreates a mime multipart object.- Returns:
- the created mime part
 
- 
getContainerGets the message container.- Returns:
- The message container.
- Since:
- 1.0
 
- 
getPrimaryBodyPartGets first body part of the message.- Returns:
- The primary body part.
- Throws:
- MessagingException- An error occurred while getting the primary body part.
- Since:
- 1.0
 
- 
getSubTypeGets the MIME subtype of the email.- Returns:
- MIME subtype of the email
- Since:
- 1.0
 
- 
initInitialize the multipart email.- Since:
- 1.0
 
- 
isBoolHasAttachmentsTests whether there are attachments.- Returns:
- true if there are attachments
- Since:
- 1.0
 
- 
isInitializedTests if this object is initialized.- Returns:
- true if initialized
 
- 
setBoolHasAttachmentsSets whether there are attachments.- Parameters:
- hasAttachments- the attachments flag
- Since:
- 1.0
 
- 
setInitializedSets the initialized status of this object.- Parameters:
- initialized- the initialized status flag
 
- 
setMsgSets the message of the email.- Specified by:
- setMsgin class- Email
- Parameters:
- msg- A String.
- Returns:
- An Email.
- Throws:
- EmailException- see javax.mail.internet.MimeBodyPart for definitions
- Since:
- 1.0
 
- 
setSubTypeSets the MIME subtype of the email.- Parameters:
- subType- MIME subtype of the email
- Since:
- 1.0
 
 
-