| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectatg.service.email.MimeMessageUtils
public class MimeMessageUtils
A set of static utility methods for creating and filling in
 javax.mail.Message objects.  In particular, the 
 createMessage methods of this class create 
 javax.mail.internet.MimeMessage objects; other 
 methods can be used to set the various fields of the message,
 specify the message content, and so on.
 
Note that the setContent methods in this 
 class typically call through to 
 javax.mail.Part.setContent(Object obj, String type) 
 to set the content of the message or each of its parts.  The
 type of the content can be any MIME type; however, for the 
 message to be sent successfully, a 
 javax.activation.DataContentHandler class for 
 the specified type should be available to the JavaMail 
 implementation.  For example, to do 
 setContent(foobar, "application/x-foobar"), a 
 DataContentHandler for "application/x-foobar"
 should be installed.  The Object passed in to the 
 setContent method should be of type expected by
 the DataContentHandler associated with the 
 content type.
 
 
If you want to create and send messages with a content 
 type unknown to the system, you will first need to write a
 DataContentHandler implementation specific to 
 your content type.  Once you have your 
 FoobarDataContentHandler, you will need to 
 make it available to the Java Activation Framework.  One way
 to do that is by providing a mailcap file with
 the new content handler entry in it (see JAF documentation,
 particularly javax.activation.MailcapCommandMap
 class documentation, for more information).  Another option
 is to provide the same information to the
 DataContentHandlerRegistry component, by 
 setting its dataContentHandlerMap property. 
 
 
Following is the list of MIME types currently supported 
 by the system, assuming a 
 DataContentHandlerRegistry component with the
 standard configuration is used.  For each content type, we 
 also indicate the type of Object that must be passed in to 
 setContent for the associated 
 DataContentHandler to work correctly:
 
String)
 String) 
 
Message, 
MimeMessage, 
DataContentHandler, 
MailcapCommandMap, 
DataContentHandlerRegistry| Field Summary | |
|---|---|
| static java.lang.String | CLASS_VERSIONClass version string | 
| Constructor Summary | |
|---|---|
| MimeMessageUtils() | |
| Method Summary | |
|---|---|
| static void | addRecipient(javax.mail.Message pMessage,
             javax.mail.Message.RecipientType pRecipientType,
             java.lang.String pRecipient)Adds a recipient to the message. | 
| static void | addRecipients(javax.mail.Message pMessage,
              javax.mail.Message.RecipientType pRecipientType,
              java.lang.String[] pRecipients)Adds recipients to the message. | 
| static javax.mail.Message | createMessage()Creates a new, empty Message object. | 
| static javax.mail.Message | createMessage(javax.mail.Session pSession)Creates a new, empty Message object. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject)Creates a new Message object with the given From and Subject fields. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              javax.mail.Session pSession)Creates a new Message object with the given From and Subject fields. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              java.lang.String pReplyTo)Creates a new Message object with the given From ReplyTo and Subject fields. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              java.lang.String pTo,
              java.lang.Object pContent,
              java.lang.String pContentType)Creates a new Message object with the given From, Subject, and To fields, and the given content. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              java.lang.String pTo,
              java.lang.Object pContent,
              java.lang.String pContentType,
              javax.mail.Session pSession)Creates a new Message object with the given From, Subject, and To fields, and the given content. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              java.lang.String pReplyTo,
              javax.mail.Session pSession)Creates a new Message object with the given From ReplyTo and Subject fields. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              java.lang.String pTo,
              java.lang.String pTextContent)Creates a new Message object with the given From, Subject, and To fields, and a body given by pTextContent. | 
| static javax.mail.Message | createMessage(java.lang.String pFrom,
              java.lang.String pSubject,
              java.lang.String pTo,
              java.lang.String pTextContent,
              javax.mail.Session pSession)Creates a new Message object with the given From, Subject, and To fields, and a body given by pTextContent. | 
| static javax.mail.Session | createSession()Creates a new mail session. | 
| static javax.mail.Session | getDefaultSession()Gets the default mail session using without using and Authenticator. | 
| static void | setBcc(javax.mail.Message pMessage,
       java.lang.String pBcc)Adds the Bcc field of the message to the InternetAddress obtained from the given string. | 
| static void | setCc(javax.mail.Message pMessage,
      java.lang.String pCc)Adds the Cc field of the message to the InternetAddress obtained from the given string. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts)Sets the message content of a message with multiple content parts. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts,
           boolean pInlineAttachments,
           javax.activation.DataHandler[] pAttachments,
           java.lang.String pMultipartSubtype)Sets the message content of a message with multiple content parts and multiple file attachments. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts,
           java.io.File[] pAttachments,
           boolean pInlineAttachments)Sets the message content of a message with multiple content parts and multiple file attachments. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts,
           java.io.File[] pAttachments,
           boolean pInlineAttachments,
           java.lang.String pMultipartSubtype)Sets the message content of a message with multiple content parts and multiple file attachments. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts,
           java.io.File pAttachment,
           boolean pInlineAttachment)Sets the message content of a message with multiple content parts and a file attachment. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts,
           java.io.File pAttachment,
           boolean pInlineAttachment,
           java.lang.String pMultipartSubtype)Sets the message content of a message with multiple content parts and a file attachment. | 
| static void | setContent(javax.mail.Message pMessage,
           ContentPart[] pContentParts,
           java.lang.String pMultipartSubtype)Sets the message content of a message with multiple content parts. | 
| static void | setContent(javax.mail.Message pMessage,
           java.lang.Object pContent,
           java.lang.String pContentType,
           java.io.File[] pAttachments,
           boolean pInlineAttachments)Sets the message content of a message with multiple file attachments. | 
| static void | setContent(javax.mail.Message pMessage,
           java.lang.Object pContent,
           java.lang.String pContentType,
           java.io.File pAttachment,
           boolean pInlineAttachment)Sets the message content of a message with a file attachment. | 
| static void | setFrom(javax.mail.Message pMessage,
        java.lang.String pFrom)Sets the From field of the message to the InternetAddress obtained from the given string. | 
| static void | setRecipient(javax.mail.Message pMessage,
             javax.mail.Message.RecipientType pRecipientType,
             java.lang.String pRecipient)Sets the recipient of the message (either To, Cc, or Bcc field) to the InternetAddress obtained from the given string. | 
| static void | setRecipients(javax.mail.Message pMessage,
              javax.mail.Message.RecipientType pRecipientType,
              java.lang.String pRecipient)Describe setRecipientsmethod here. | 
| static void | setRecipients(javax.mail.Message pMessage,
              javax.mail.Message.RecipientType pRecipientType,
              java.lang.String[] pRecipients)Sets the recipients of the message (either To, Cc, or Bcc field) to the InternetAddress array obtained from the given string array. | 
| static void | setReplyTo(javax.mail.Message pMessage,
           java.lang.String pReplyTo)Sets the ReplyTo field of the message to the InternetAddress obtained from the given string. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static java.lang.String CLASS_VERSION
| Constructor Detail | 
|---|
public MimeMessageUtils()
| Method Detail | 
|---|
public static javax.mail.Session createSession()
Session.getInstance(java.util.Properties,javax.mail.Authenticator);public static javax.mail.Session getDefaultSession()
Session.getDefaultInstance(java.util.Properties,javax.mail.Authenticator);, 
Authenticatorpublic static javax.mail.Message createMessage()
public static javax.mail.Message createMessage(javax.mail.Session pSession)
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject)
                                        throws javax.mail.MessagingException
javax.mail.MessagingException - if any of the fields could not 
 be set
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               javax.mail.Session pSession)
                                        throws javax.mail.MessagingException
javax.mail.MessagingException - if any of the fields could not 
 be set
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               java.lang.String pReplyTo)
                                        throws javax.mail.MessagingException
javax.mail.MessagingException - if any of the fields could not 
 be set
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               java.lang.String pReplyTo,
                                               javax.mail.Session pSession)
                                        throws javax.mail.MessagingException
javax.mail.MessagingException - if any of the fields could not 
 be set
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               java.lang.String pTo,
                                               java.lang.String pTextContent)
                                        throws javax.mail.MessagingException
pTextContent.
 This is a convenience method that calls 
 MimeMessage.setText(pTextContent) to set the 
 message content; the resulting MIME type of the content is 
 "text/plain."
javax.mail.MessagingException - if any of the fields or the 
 message content could not be setMimeMessage.setText(String)
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               java.lang.String pTo,
                                               java.lang.String pTextContent,
                                               javax.mail.Session pSession)
                                        throws javax.mail.MessagingException
pTextContent.
 This is a convenience method that calls 
 MimeMessage.setText(pTextContent) to set the 
 message content; the resulting MIME type of the content is 
 "text/plain."
javax.mail.MessagingException - if any of the fields or the 
 message content could not be setMimeMessage.setText(String)
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               java.lang.String pTo,
                                               java.lang.Object pContent,
                                               java.lang.String pContentType)
                                        throws javax.mail.MessagingException
MimeMessage.setContent(pContent, pContentType)
 to set the message content.
javax.mail.MessagingException - if any of the fields or the 
 message content could not be setMimeMessage.setContent(Object, String)
public static javax.mail.Message createMessage(java.lang.String pFrom,
                                               java.lang.String pSubject,
                                               java.lang.String pTo,
                                               java.lang.Object pContent,
                                               java.lang.String pContentType,
                                               javax.mail.Session pSession)
                                        throws javax.mail.MessagingException
MimeMessage.setContent(pContent, pContentType)
 to set the message content.
javax.mail.MessagingException - if any of the fields or the 
 message content could not be setMimeMessage.setContent(Object, String)
public static void setReplyTo(javax.mail.Message pMessage,
                              java.lang.String pReplyTo)
                       throws javax.mail.MessagingException
javax.mail.MessagingException - if the field could not be set
public static void setFrom(javax.mail.Message pMessage,
                           java.lang.String pFrom)
                    throws javax.mail.MessagingException
javax.mail.MessagingException - if the field could not be set
public static void setCc(javax.mail.Message pMessage,
                         java.lang.String pCc)
                  throws javax.mail.MessagingException
javax.mail.MessagingException - if the field could not be set
public static void setBcc(javax.mail.Message pMessage,
                          java.lang.String pBcc)
                   throws javax.mail.MessagingException
javax.mail.MessagingException - if the field could not be set
public static void setRecipient(javax.mail.Message pMessage,
                                javax.mail.Message.RecipientType pRecipientType,
                                java.lang.String pRecipient)
                         throws javax.mail.MessagingException
pRecipientType - the recipient type, given by one of the 
 values enumerated in Message.RecipientType; e.g., specifying 
 Message.RecipientType.TO for the recipient type will result in 
 the To field being set
javax.mail.MessagingException - if the field could not be setMessage.RecipientType
public static void setRecipients(javax.mail.Message pMessage,
                                 javax.mail.Message.RecipientType pRecipientType,
                                 java.lang.String[] pRecipients)
                          throws javax.mail.MessagingException
pRecipientType - the recipient type, given by one of the 
 values enumerated in Message.RecipientType; e.g., specifying 
 Message.RecipientType.TO for the recipient type will result in 
 the To field being set
javax.mail.MessagingException - if the field could not be setMessage.RecipientType
public static void setRecipients(javax.mail.Message pMessage,
                                 javax.mail.Message.RecipientType pRecipientType,
                                 java.lang.String pRecipient)
                          throws javax.mail.MessagingException
setRecipients method here.
pMessage - a Message valuepRecipientType - a Message.RecipientType valuepRecipient - a String value
javax.mail.MessagingException
public static void addRecipient(javax.mail.Message pMessage,
                                javax.mail.Message.RecipientType pRecipientType,
                                java.lang.String pRecipient)
                         throws javax.mail.MessagingException
pRecipientType - the recipient type, given by one of the 
 values enumerated in Message.RecipientType; e.g., specifying 
 Message.RecipientType.TO for the recipient type will result in 
 the To field being updated
javax.mail.MessagingException - if the field could not be setMessage.RecipientType
public static void addRecipients(javax.mail.Message pMessage,
                                 javax.mail.Message.RecipientType pRecipientType,
                                 java.lang.String[] pRecipients)
                          throws javax.mail.MessagingException
pRecipientType - the recipient type, given by one of the 
 values enumerated in Message.RecipientType; e.g., specifying 
 Message.RecipientType.TO for the recipient type will result in 
 the To field being updated
javax.mail.MessagingException - if the field could not be setMessage.RecipientType
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 with a content type of "multipart/mixed;" for each 
 contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts,
                              java.lang.String pMultipartSubtype)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 with a content type of 
 "multipart/pMultipartSubtype"; for each 
 contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)
public static void setContent(javax.mail.Message pMessage,
                              java.lang.Object pContent,
                              java.lang.String pContentType,
                              java.io.File pAttachment,
                              boolean pInlineAttachment)
                       throws javax.mail.MessagingException
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed"); the first part
 is given by pContent, with the MIME type of 
 pContentType, and the second part contains the
 file attachment.
pAttachment - the file to attach to the messagepInlineAttachment - if true, the file will be inlined 
 into the message, rather than attached
javax.mail.MessagingException - if the message content could
 not be set
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts,
                              java.io.File pAttachment,
                              boolean pInlineAttachment)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed").  The first part 
 of the multipart is itself a MimeMultipart, with a content 
 type of "multipart/mixed;" for each contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.  The second part of the outer multipart 
 contains the file attachment.
pAttachment - the file to attach to the messagepInlineAttachment - if true, the file will be inlined 
 into the message, rather than attached
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts,
                              java.io.File pAttachment,
                              boolean pInlineAttachment,
                              java.lang.String pMultipartSubtype)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed").  The first part 
 of the multipart is itself a MimeMultipart, with a content 
 type of "multipart/pMultipartSubtype;" for each 
 contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.  The second part of the outer multipart 
 contains the file attachment.
pAttachment - the file to attach to the messagepInlineAttachment - if true, the file will be inlined 
 into the message, rather than attached
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)
public static void setContent(javax.mail.Message pMessage,
                              java.lang.Object pContent,
                              java.lang.String pContentType,
                              java.io.File[] pAttachments,
                              boolean pInlineAttachments)
                       throws javax.mail.MessagingException
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed"); the first part
 is given by pContent, with the MIME type of 
 pContentType, and the rest of the parts 
 contain the file attachments.
pAttachments - the files to attach to the messagepInlineAttachment - if true, each of the files will be 
 inlined into the message, rather than attached
javax.mail.MessagingException - if the message content could
 not be set
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts,
                              java.io.File[] pAttachments,
                              boolean pInlineAttachments)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed").  The first part
 of the multipart is itself a MimeMultipart, with a content
 type of "multipart/mixed;" for each contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.  Additional parts of the outer multipart
 contain the file attachments.
pAttachments - the files to attach to the messagepInlineAttachments - if true, each of the files will be 
 inlined into the message, rather than attached
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts,
                              java.io.File[] pAttachments,
                              boolean pInlineAttachments,
                              java.lang.String pMultipartSubtype)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed").  The first part
 of the multipart is itself a MimeMultipart, with a content
 type of "multipart/pMultipartSubtype;" for each 
 contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.  Additional parts of the outer multipart
 contain the file attachments.
pAttachments - the files to attach to the messagepInlineAttachments - if true, each of the files will be 
 inlined into the message, rather than attached
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)
public static void setContent(javax.mail.Message pMessage,
                              ContentPart[] pContentParts,
                              boolean pInlineAttachments,
                              javax.activation.DataHandler[] pAttachments,
                              java.lang.String pMultipartSubtype)
                       throws javax.mail.MessagingException
Each element in pContentParts represents a 
 message part, with the content and its MIME type contained
 within the ContentPart object.
 
 
This method sets the message content to a MimeMultipart
 (with a content type of "multipart/mixed").  The first part
 of the multipart is itself a MimeMultipart, with a content
 type of "multipart/pMultipartSubtype;" for each 
 contentPart,
 Part.setContent(contentPart.getContent(), 
 contentPart.getContentType()) is called to set the 
 part's content.  Additional parts of the outer multipart
 contain the file attachments.
pInlineAttachments - if true, each of the files will be 
 inlined into the message, rather than attachedpAttachments - the DataHandlers representing the files
                     to attach to the message
javax.mail.MessagingException - if the message content could
 not be setPart.setContent(Object, String)| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||