org.apache.commons.mail
Class MultiPartEmail

java.lang.Object
  extended byorg.apache.commons.mail.Email
      extended byorg.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
Version:
$Id: MultiPartEmail.java 279285 2005-09-07 09:52:44Z henning $
Author:
Quinton McCombs, Jon S. Stevens, Frank Y. Kim, Brett McLaughlin, Regis Koenig, Corey Scott

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_FROM, MAIL_TRANSPORT_PROTOCOL, message, popBeforeSmtp, popHost, popPassword, popUsername, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, sentDate, SMTP, smtpPort, subject, TEXT_HTML, TEXT_PLAIN, toList, US_ASCII
 
Constructor Summary
MultiPartEmail()
           
 
Method Summary
 Email addPart(javax.mail.internet.MimeMultipart multipart)
          Add a new part to the email.
 Email addPart(javax.mail.internet.MimeMultipart multipart, int index)
          Add a new part to the email.
 Email addPart(java.lang.String partContent, java.lang.String partContentType)
          Add a new part to the email.
 MultiPartEmail attach(javax.activation.DataSource ds, java.lang.String name, java.lang.String description)
          Attach a file specified as a DataSource interface.
 MultiPartEmail attach(javax.activation.DataSource ds, java.lang.String name, java.lang.String description, java.lang.String disposition)
          Attach a file specified as a DataSource interface.
 MultiPartEmail attach(EmailAttachment attachment)
          Attach an EmailAttachment.
 MultiPartEmail attach(java.net.URL url, java.lang.String name, java.lang.String description)
          Attach a file located by its URL.
 MultiPartEmail attach(java.net.URL url, java.lang.String name, java.lang.String description, java.lang.String disposition)
          Attach a file located by its URL.
 void buildMimeMessage()
          Builds the actual MimeMessage
protected  javax.mail.BodyPart createBodyPart()
          Method that can be overridden if you don't want to create a MimeBodyPart.
protected  javax.mail.internet.MimeMultipart createMimeMultipart()
           
protected  javax.mail.internet.MimeMultipart getContainer()
          Gets the message container.
protected  javax.mail.BodyPart getPrimaryBodyPart()
          Gets first body part of the message.
 java.lang.String getSubType()
          Get the MIME subtype of the email.
protected  void init()
          Initialize the multipart email.
 boolean isBoolHasAttachments()
           
protected  boolean isInitialized()
           
 void setBoolHasAttachments(boolean b)
           
protected  void setInitialized(boolean b)
           
 Email setMsg(java.lang.String msg)
          Set the message of the email.
 void setSubType(java.lang.String aSubType)
          Set the MIME subtype of the email.
 
Methods inherited from class org.apache.commons.mail.Email
addBcc, addBcc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addTo, addTo, getFromAddress, getHostName, getMailSession, getMimeMessage, getSentDate, getSmtpPort, getSubject, send, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setFrom, setFrom, setHeaders, setHostName, setMailSession, setPopBeforeSmtp, setSentDate, setSmtpPort, setSubject, setTo, toInternetAddressArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiPartEmail

public MultiPartEmail()
Method Detail

setSubType

public void setSubType(java.lang.String aSubType)
Set the MIME subtype of the email.

Parameters:
aSubType - MIME subtype of the email
Since:
1.0

getSubType

public java.lang.String getSubType()
Get the MIME subtype of the email.

Returns:
MIME subtype of the email
Since:
1.0

addPart

public Email addPart(java.lang.String partContent,
                     java.lang.String partContentType)
              throws EmailException
Add 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

addPart

public Email addPart(javax.mail.internet.MimeMultipart multipart)
              throws EmailException
Add 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
Add 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 occured while adding the part.
Since:
1.0

init

protected void init()
Initialize the multipart email.

Since:
1.0

setMsg

public Email setMsg(java.lang.String msg)
             throws EmailException
Set the message of the email.

Specified by:
setMsg in class Email
Parameters:
msg - A String.
Returns:
An Email.
Throws:
EmailException - see javax.mail.internet.MimeBodyPart for definitions
Since:
1.0

buildMimeMessage

public void buildMimeMessage()
                      throws EmailException
Builds the actual MimeMessage

Overrides:
buildMimeMessage in class Email
Throws:
EmailException - see javax.mail.internet.MimeBodyPart for definitions
Since:
1.0

attach

public MultiPartEmail attach(EmailAttachment attachment)
                      throws EmailException
Attach 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.net.URL url,
                             java.lang.String name,
                             java.lang.String description)
                      throws EmailException
Attach 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
Attach 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

attach

public MultiPartEmail attach(javax.activation.DataSource ds,
                             java.lang.String name,
                             java.lang.String description)
                      throws EmailException
Attach a file specified as a DataSource interface.

Parameters:
ds - 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 ds,
                             java.lang.String name,
                             java.lang.String description,
                             java.lang.String disposition)
                      throws EmailException
Attach a file specified as a DataSource interface.

Parameters:
ds - 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

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 occured while getting the primary body part.
Since:
1.0

getContainer

protected javax.mail.internet.MimeMultipart getContainer()
Gets the message container.

Returns:
The message container.
Since:
1.0

createBodyPart

protected javax.mail.BodyPart createBodyPart()
Method that can be overridden if you don't want to create a MimeBodyPart.

Returns:

createMimeMultipart

protected javax.mail.internet.MimeMultipart createMimeMultipart()
Returns:

isBoolHasAttachments

public boolean isBoolHasAttachments()
Returns:
boolHasAttachments
Since:
1.0

setBoolHasAttachments

public void setBoolHasAttachments(boolean b)
Parameters:
b - boolHasAttachments
Since:
1.0

isInitialized

protected boolean isInitialized()
Returns:

setInitialized

protected void setInitialized(boolean b)
Parameters:
b -


Copyright © 2001-2007 The Apache Software Foundation. All Rights Reserved.