Java Doc for MimeMessageHelper.java in  » J2EE » spring-framework-2.0.6 » org » springframework » mail » javamail » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.mail.javamail 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.mail.javamail.MimeMessageHelper

MimeMessageHelper
public class MimeMessageHelper (Code)
Helper class for populating a javax.mail.internet.MimeMessage .

Mirrors the simple setters of org.springframework.mail.SimpleMailMessage , directly applying the values to the underlying MimeMessage. Allows for defining a character encoding for the entire message, automatically applied by all methods of this helper class.

Offers support for HTML text content, inline elements such as images, and typical mail attachments. Also supports personal names that accompany mail addresses. Note that advanced settings can still be applied directly to the underlying MimeMessage object!

Typically used in MimeMessagePreparator implementations or JavaMailSender client code: simply instantiating it as a MimeMessage wrapper, invoking setters on the wrapper, using the underlying MimeMessage for mail sending. Also used internally by JavaMailSenderImpl .

Sample code for an HTML mail with an inline image and a PDF attachment:

 mailSender.send(new MimeMessagePreparator() {
 public void prepare(MimeMessage mimeMessage) throws MessagingException {
 MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
 message.setFrom("me@mail.com");
 message.setTo("you@mail.com");
 message.setSubject("my subject");
 message.setText("my text <img src='cid:myLogo'>", true);
 message.addInline("myLogo", new ClassPathResource("img/mylogo.gif"));
 message.addAttachment("myDocument.pdf", new ClassPathResource("doc/myDocument.pdf"));
 }
 });
Consider using MimeMailMessage (which implements the common org.springframework.mail.MailMessage interface, just like org.springframework.mail.SimpleMailMessage ) on top of this helper, in order to let message population code interact with a simple message or a MIME message through a common interface.

Warning regarding multipart mails: Simple MIME messages that just contain HTML text but no inline elements or attachments will work on more or less any email client that is capable of HTML rendering. However, inline elements and attachments are still a major compatibility issue between email clients: It's virtually impossible to get inline elements and attachments working across Microsoft Outlook, Lotus Notes and Mac Mail. Consider choosing a specific multipart mode for your needs: The javadoc on the MULTIPART_MODE constants contains more detailed information.
author:
   Juergen Hoeller
since:
   19.01.2004
See Also:   MimeMessageHelper.setText(String,boolean)
See Also:   MimeMessageHelper.setText(String,String)
See Also:   MimeMessageHelper.addInline(String,org.springframework.core.io.Resource)
See Also:   MimeMessageHelper.addAttachment(String,org.springframework.core.io.InputStreamSource)
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED
See Also:   MimeMessageHelper.MULTIPART_MODE_RELATED
See Also:   MimeMessageHelper.getMimeMessage()
See Also:   JavaMailSender



Field Summary
final public static  intMULTIPART_MODE_MIXED
     Constant indicating a multipart message with a single root multipart element of type "mixed".
final public static  intMULTIPART_MODE_MIXED_RELATED
     Constant indicating a multipart message with a root multipart element "mixed" plus a nested multipart element of type "related".
final public static  intMULTIPART_MODE_NO
     Constant indicating a non-multipart message.
final public static  intMULTIPART_MODE_RELATED
     Constant indicating a multipart message with a single root multipart element of type "related".

Constructor Summary
public  MimeMessageHelper(MimeMessage mimeMessage)
     Create a new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content, i.e.
public  MimeMessageHelper(MimeMessage mimeMessage, String encoding)
     Create a new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content, i.e.
public  MimeMessageHelper(MimeMessage mimeMessage, boolean multipart)
     Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

Consider using the MimeMessageHelper constructor that takes a multipartMode argument to choose a specific multipart mode other than MULTIPART_MODE_MIXED_RELATED.

The character encoding for the message will be taken from the passed-in MimeMessage object, if carried there.

public  MimeMessageHelper(MimeMessage mimeMessage, boolean multipart, String encoding)
     Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.
public  MimeMessageHelper(MimeMessage mimeMessage, int multipartMode)
     Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

The character encoding for the message will be taken from the passed-in MimeMessage object, if carried there.

public  MimeMessageHelper(MimeMessage mimeMessage, int multipartMode, String encoding)
     Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

Method Summary
public  voidaddAttachment(String attachmentFilename, DataSource dataSource)
     Add an attachment to the MimeMessage, taking the content from a javax.activation.DataSource.
public  voidaddAttachment(String attachmentFilename, File file)
     Add an attachment to the MimeMessage, taking the content from a java.io.File.

The content type will be determined by the name of the given content file.

public  voidaddAttachment(String attachmentFilename, InputStreamSource inputStreamSource)
     Add an attachment to the MimeMessage, taking the content from an org.springframework.core.io.InputStreamResource.

The content type will be determined by the given filename for the attachment.

public  voidaddAttachment(String attachmentFilename, InputStreamSource inputStreamSource, String contentType)
     Add an attachment to the MimeMessage, taking the content from an org.springframework.core.io.InputStreamResource.
public  voidaddBcc(InternetAddress bcc)
    
public  voidaddBcc(String bcc)
    
public  voidaddBcc(String bcc, String personal)
    
public  voidaddCc(InternetAddress cc)
    
public  voidaddCc(String cc)
    
public  voidaddCc(String cc, String personal)
    
public  voidaddInline(String contentId, DataSource dataSource)
     Add an inline element to the MimeMessage, taking the content from a javax.activation.DataSource.

Note that the InputStream returned by the DataSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.

NOTE: Invoke addInline after MimeMessageHelper.setText ; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  contentId - the content ID to use.

public  voidaddInline(String contentId, File file)
     Add an inline element to the MimeMessage, taking the content from a java.io.File.

The content type will be determined by the name of the given content file.

public  voidaddInline(String contentId, Resource resource)
     Add an inline element to the MimeMessage, taking the content from a org.springframework.core.io.Resource.

The content type will be determined by the name of the given content file.

public  voidaddInline(String contentId, InputStreamSource inputStreamSource, String contentType)
     Add an inline element to the MimeMessage, taking the content from an org.springframework.core.InputStreamResource, and specifying the content type explicitly.

You can determine the content type for any given filename via a Java Activation Framework's FileTypeMap, for example the one held by this helper.

Note that the InputStream returned by the InputStreamSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.

NOTE: Invoke addInline after setText; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  contentId - the content ID to use.

public  voidaddTo(InternetAddress to)
    
public  voidaddTo(String to)
    
public  voidaddTo(String to, String personal)
    
protected  DataSourcecreateDataSource(InputStreamSource inputStreamSource, String contentType, String name)
     Create an Activation Framework DataSource for the given InputStreamSource.
protected  voidcreateMimeMultiparts(MimeMessage mimeMessage, int multipartMode)
     Determine the MimeMultipart objects to use, which will be used to store attachments on the one hand and text(s) and inline elements on the other hand.
protected  StringgetDefaultEncoding(MimeMessage mimeMessage)
     Determine the default encoding for the given MimeMessage.
protected  FileTypeMapgetDefaultFileTypeMap(MimeMessage mimeMessage)
     Determine the default Java Activation FileTypeMap for the given MimeMessage.
public  StringgetEncoding()
     Return the specific character encoding used for this message, if any.
public  FileTypeMapgetFileTypeMap()
     Return the FileTypeMap used by this MimeMessageHelper.
final public  MimeMessagegetMimeMessage()
     Return the underlying MimeMessage object.
final public  MimeMultipartgetMimeMultipart()
     Return the underlying MIME "multipart/related" object, if any.
final public  MimeMultipartgetRootMimeMultipart()
     Return the root MIME "multipart/mixed" object, if any.
final public  booleanisMultipart()
     Return whether this helper is in multipart mode, i.e.
public  booleanisValidateAddresses()
     Return whether this helper will validate all addresses passed to it.
public  voidsetBcc(InternetAddress bcc)
    
public  voidsetBcc(InternetAddress[] bcc)
    
public  voidsetBcc(String bcc)
    
public  voidsetBcc(String[] bcc)
    
public  voidsetCc(InternetAddress cc)
    
public  voidsetCc(InternetAddress[] cc)
    
public  voidsetCc(String cc)
    
public  voidsetCc(String[] cc)
    
public  voidsetFileTypeMap(FileTypeMap fileTypeMap)
     Set the Java Activation Framework FileTypeMap to use for determining the content type of inline content and attachments that get added to the message.
public  voidsetFrom(InternetAddress from)
    
public  voidsetFrom(String from)
    
public  voidsetFrom(String from, String personal)
    
final protected  voidsetMimeMultiparts(MimeMultipart root, MimeMultipart main)
     Set the given MimeMultipart objects for use by this MimeMessageHelper.
public  voidsetPriority(int priority)
     Set the priority ("X-Priority" header) of the message.
public  voidsetReplyTo(InternetAddress replyTo)
    
public  voidsetReplyTo(String replyTo)
    
public  voidsetReplyTo(String replyTo, String personal)
    
public  voidsetSentDate(Date sentDate)
     Set the sent-date of the message.
public  voidsetSubject(String subject)
     Set the subject of the message, using the correct encoding.
public  voidsetText(String text)
     Set the given text directly as content in non-multipart mode or as default body part in multipart mode.
public  voidsetText(String text, boolean html)
     Set the given text directly as content in non-multipart mode or as default body part in multipart mode.
public  voidsetText(String plainText, String htmlText)
     Set the given plain text and HTML text as alternatives, offering both options to the email client.
public  voidsetTo(InternetAddress to)
    
public  voidsetTo(InternetAddress[] to)
    
public  voidsetTo(String to)
    
public  voidsetTo(String[] to)
    
public  voidsetValidateAddresses(boolean validateAddresses)
     Set whether to validate all addresses which get passed to this helper.
protected  voidvalidateAddress(InternetAddress address)
     Validate the given mail address. Called by all of MimeMessageHelper's address setters and adders.

Default implementation invokes InternetAddress.validate(), provided that address validation is activated for the helper instance.

Note that this method will just work on JavaMail >= 1.3.

protected  voidvalidateAddresses(InternetAddress[] addresses)
     Validate all given mail addresses.

Field Detail
MULTIPART_MODE_MIXED
final public static int MULTIPART_MODE_MIXED(Code)
Constant indicating a multipart message with a single root multipart element of type "mixed". Texts, inline elements and attachements will all get added to that root element.

This was Spring 1.0's default behavior. It is known to work properly on Outlook. However, other mail clients tend to misinterpret inline elements as attachments and/or show attachments inline as well.




MULTIPART_MODE_MIXED_RELATED
final public static int MULTIPART_MODE_MIXED_RELATED(Code)
Constant indicating a multipart message with a root multipart element "mixed" plus a nested multipart element of type "related". Texts and inline elements will get added to the nested "related" element, while attachments will get added to the "mixed" root element.

This is the default since Spring 1.2.1. This is arguably the most correct MIME structure, according to the MIME spec: It is known to work properly on Outlook, Outlook Express, Yahoo Mail, and Lotus Notes. Does not work properly on Mac Mail. If you target Mac Mail or experience issues with specific mails on Outlook, consider using MULTIPART_MODE_RELATED instead.




MULTIPART_MODE_NO
final public static int MULTIPART_MODE_NO(Code)
Constant indicating a non-multipart message.



MULTIPART_MODE_RELATED
final public static int MULTIPART_MODE_RELATED(Code)
Constant indicating a multipart message with a single root multipart element of type "related". Texts, inline elements and attachements will all get added to that root element.

This was the default behavior from Spring 1.1 up to 1.2 final. This is the "Microsoft multipart mode", as natively sent by Outlook. It is known to work properly on Outlook, Outlook Express, Yahoo Mail, and to a large degree also on Mac Mail (with an additional attachment listed for an inline element, despite the inline element also shown inline). Does not work properly on Lotus Notes (attachments won't be shown there).





Constructor Detail
MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage)(Code)
Create a new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content, i.e. no alternative texts and no inline elements or attachments).

The character encoding for the message will be taken from the passed-in MimeMessage object, if carried there. Else, JavaMail's default encoding will be used.
Parameters:
  mimeMessage - MimeMessage to work on
See Also:   MimeMessageHelper.MimeMessageHelper(javax.mail.internet.MimeMessage,boolean)
See Also:   MimeMessageHelper.getDefaultEncoding(javax.mail.internet.MimeMessage)
See Also:   JavaMailSenderImpl.setDefaultEncoding




MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage, String encoding)(Code)
Create a new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content, i.e. no alternative texts and no inline elements or attachments).
Parameters:
  mimeMessage - MimeMessage to work on
Parameters:
  encoding - the character encoding to use for the message
See Also:   MimeMessageHelper.MimeMessageHelper(javax.mail.internet.MimeMessage,boolean)



MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage, boolean multipart) throws MessagingException(Code)
Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

Consider using the MimeMessageHelper constructor that takes a multipartMode argument to choose a specific multipart mode other than MULTIPART_MODE_MIXED_RELATED.

The character encoding for the message will be taken from the passed-in MimeMessage object, if carried there. Else, JavaMail's default encoding will be used.
Parameters:
  mimeMessage - MimeMessage to work on
Parameters:
  multipart - whether to create a multipart message thatsupports alternative texts, inline elements and attachments(corresponds to MULTIPART_MODE_MIXED_RELATED)
throws:
  MessagingException - if multipart creation failed
See Also:   MimeMessageHelper.MimeMessageHelper(javax.mail.internet.MimeMessage,int)
See Also:   MimeMessageHelper.getDefaultEncoding(javax.mail.internet.MimeMessage)
See Also:   JavaMailSenderImpl.setDefaultEncoding




MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage, boolean multipart, String encoding) throws MessagingException(Code)
Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

Consider using the MimeMessageHelper constructor that takes a multipartMode argument to choose a specific multipart mode other than MULTIPART_MODE_MIXED_RELATED.
Parameters:
  mimeMessage - MimeMessage to work on
Parameters:
  multipart - whether to create a multipart message thatsupports alternative texts, inline elements and attachments(corresponds to MULTIPART_MODE_MIXED_RELATED)
Parameters:
  encoding - the character encoding to use for the message
throws:
  MessagingException - if multipart creation failed
See Also:   MimeMessageHelper.MimeMessageHelper(javax.mail.internet.MimeMessage,int,String)




MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage, int multipartMode) throws MessagingException(Code)
Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

The character encoding for the message will be taken from the passed-in MimeMessage object, if carried there. Else, JavaMail's default encoding will be used.
Parameters:
  mimeMessage - MimeMessage to work on
Parameters:
  multipartMode - which kind of multipart message to create(MIXED, RELATED, MIXED_RELATED, or NO)
throws:
  MessagingException - if multipart creation failed
See Also:   MimeMessageHelper.MULTIPART_MODE_NO
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED
See Also:   MimeMessageHelper.MULTIPART_MODE_RELATED
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED
See Also:   MimeMessageHelper.getDefaultEncoding(javax.mail.internet.MimeMessage)
See Also:   JavaMailSenderImpl.setDefaultEncoding




MimeMessageHelper
public MimeMessageHelper(MimeMessage mimeMessage, int multipartMode, String encoding) throws MessagingException(Code)
Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.
Parameters:
  mimeMessage - MimeMessage to work on
Parameters:
  multipartMode - which kind of multipart message to create(MIXED, RELATED, MIXED_RELATED, or NO)
Parameters:
  encoding - the character encoding to use for the message
throws:
  MessagingException - if multipart creation failed
See Also:   MimeMessageHelper.MULTIPART_MODE_NO
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED
See Also:   MimeMessageHelper.MULTIPART_MODE_RELATED
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED




Method Detail
addAttachment
public void addAttachment(String attachmentFilename, DataSource dataSource) throws MessagingException(Code)
Add an attachment to the MimeMessage, taking the content from a javax.activation.DataSource.

Note that the InputStream returned by the DataSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.
Parameters:
  attachmentFilename - the name of the attachment as it willappear in the mail (the content type will be determined by this)
Parameters:
  dataSource - the javax.activation.DataSource to takethe content from, determining the InputStream and the content type
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.addAttachment(String,org.springframework.core.io.InputStreamSource)
See Also:   MimeMessageHelper.addAttachment(String,java.io.File)




addAttachment
public void addAttachment(String attachmentFilename, File file) throws MessagingException(Code)
Add an attachment to the MimeMessage, taking the content from a java.io.File.

The content type will be determined by the name of the given content file. Do not use this for temporary files with arbitrary filenames (possibly ending in ".tmp" or the like)!
Parameters:
  attachmentFilename - the name of the attachment as it willappear in the mail
Parameters:
  file - the File resource to take the content from
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.addAttachment(String,org.springframework.core.io.InputStreamSource)
See Also:   MimeMessageHelper.addAttachment(String,javax.activation.DataSource)




addAttachment
public void addAttachment(String attachmentFilename, InputStreamSource inputStreamSource) throws MessagingException(Code)
Add an attachment to the MimeMessage, taking the content from an org.springframework.core.io.InputStreamResource.

The content type will be determined by the given filename for the attachment. Thus, any content source will be fine, including temporary files with arbitrary filenames.

Note that the InputStream returned by the InputStreamSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.
Parameters:
  attachmentFilename - the name of the attachment as it willappear in the mail
Parameters:
  inputStreamSource - the resource to take the content from(all of Spring's Resource implementations can be passed in here)
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.addAttachment(String,java.io.File)
See Also:   MimeMessageHelper.addAttachment(String,javax.activation.DataSource)
See Also:   org.springframework.core.io.Resource




addAttachment
public void addAttachment(String attachmentFilename, InputStreamSource inputStreamSource, String contentType) throws MessagingException(Code)
Add an attachment to the MimeMessage, taking the content from an org.springframework.core.io.InputStreamResource.

Note that the InputStream returned by the InputStreamSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.
Parameters:
  attachmentFilename - the name of the attachment as it willappear in the mail
Parameters:
  inputStreamSource - the resource to take the content from(all of Spring's Resource implementations can be passed in here)
Parameters:
  contentType - the content type to use for the element
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.addAttachment(String,java.io.File)
See Also:   MimeMessageHelper.addAttachment(String,javax.activation.DataSource)
See Also:   org.springframework.core.io.Resource




addBcc
public void addBcc(InternetAddress bcc) throws MessagingException(Code)



addBcc
public void addBcc(String bcc) throws MessagingException(Code)



addBcc
public void addBcc(String bcc, String personal) throws MessagingException, UnsupportedEncodingException(Code)



addCc
public void addCc(InternetAddress cc) throws MessagingException(Code)



addCc
public void addCc(String cc) throws MessagingException(Code)



addCc
public void addCc(String cc, String personal) throws MessagingException, UnsupportedEncodingException(Code)



addInline
public void addInline(String contentId, DataSource dataSource) throws MessagingException(Code)
Add an inline element to the MimeMessage, taking the content from a javax.activation.DataSource.

Note that the InputStream returned by the DataSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.

NOTE: Invoke addInline after MimeMessageHelper.setText ; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  contentId - the content ID to use. Will end up as "Content-ID" headerin the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>".Can be referenced in HTML source via src="cid:myId" expressions.
Parameters:
  dataSource - the javax.activation.DataSource to takethe content from, determining the InputStream and the content type
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.addInline(String,java.io.File)
See Also:   MimeMessageHelper.addInline(String,org.springframework.core.io.Resource)




addInline
public void addInline(String contentId, File file) throws MessagingException(Code)
Add an inline element to the MimeMessage, taking the content from a java.io.File.

The content type will be determined by the name of the given content file. Do not use this for temporary files with arbitrary filenames (possibly ending in ".tmp" or the like)!

NOTE: Invoke addInline after MimeMessageHelper.setText ; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  contentId - the content ID to use. Will end up as "Content-ID" headerin the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>".Can be referenced in HTML source via src="cid:myId" expressions.
Parameters:
  file - the File resource to take the content from
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.setText
See Also:   MimeMessageHelper.addInline(String,org.springframework.core.io.Resource)
See Also:   MimeMessageHelper.addInline(String,javax.activation.DataSource)




addInline
public void addInline(String contentId, Resource resource) throws MessagingException(Code)
Add an inline element to the MimeMessage, taking the content from a org.springframework.core.io.Resource.

The content type will be determined by the name of the given content file. Do not use this for temporary files with arbitrary filenames (possibly ending in ".tmp" or the like)!

Note that the InputStream returned by the Resource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.

NOTE: Invoke addInline after MimeMessageHelper.setText ; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  contentId - the content ID to use. Will end up as "Content-ID" headerin the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>".Can be referenced in HTML source via src="cid:myId" expressions.
Parameters:
  resource - the resource to take the content from
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.setText
See Also:   MimeMessageHelper.addInline(String,java.io.File)
See Also:   MimeMessageHelper.addInline(String,javax.activation.DataSource)




addInline
public void addInline(String contentId, InputStreamSource inputStreamSource, String contentType) throws MessagingException(Code)
Add an inline element to the MimeMessage, taking the content from an org.springframework.core.InputStreamResource, and specifying the content type explicitly.

You can determine the content type for any given filename via a Java Activation Framework's FileTypeMap, for example the one held by this helper.

Note that the InputStream returned by the InputStreamSource implementation needs to be a fresh one on each call, as JavaMail will invoke getInputStream() multiple times.

NOTE: Invoke addInline after setText; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  contentId - the content ID to use. Will end up as "Content-ID" headerin the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>".Can be referenced in HTML source via src="cid:myId" expressions.
Parameters:
  inputStreamSource - the resource to take the content from
Parameters:
  contentType - the content type to use for the element
throws:
  MessagingException - in case of errors
See Also:   MimeMessageHelper.setText
See Also:   MimeMessageHelper.getFileTypeMap
See Also:   MimeMessageHelper.addInline(String,org.springframework.core.io.Resource)
See Also:   MimeMessageHelper.addInline(String,javax.activation.DataSource)




addTo
public void addTo(InternetAddress to) throws MessagingException(Code)



addTo
public void addTo(String to) throws MessagingException(Code)



addTo
public void addTo(String to, String personal) throws MessagingException, UnsupportedEncodingException(Code)



createDataSource
protected DataSource createDataSource(InputStreamSource inputStreamSource, String contentType, String name)(Code)
Create an Activation Framework DataSource for the given InputStreamSource.
Parameters:
  inputStreamSource - the InputStreamSource (typically a Spring Resource)
Parameters:
  contentType - the content type
Parameters:
  name - the name of the DataSource the Activation Framework DataSource



createMimeMultiparts
protected void createMimeMultiparts(MimeMessage mimeMessage, int multipartMode) throws MessagingException(Code)
Determine the MimeMultipart objects to use, which will be used to store attachments on the one hand and text(s) and inline elements on the other hand.

Texts and inline elements can either be stored in the root element itself (MULTIPART_MODE_MIXED, MULTIPART_MODE_RELATED) or in a nested element rather than the root element directly (MULTIPART_MODE_MIXED_RELATED).

By default, the root MimeMultipart element will be of type "mixed" (MULTIPART_MODE_MIXED) or "related" (MULTIPART_MODE_RELATED). The main multipart element will either be added as nested element of type "related" (MULTIPART_MODE_MIXED_RELATED) or be identical to the root element itself (MULTIPART_MODE_MIXED, MULTIPART_MODE_RELATED).
Parameters:
  mimeMessage - the MimeMessage object to add the root MimeMultipartobject to
Parameters:
  multipartMode - the multipart mode, as passed into the constructor(MIXED, RELATED, MIXED_RELATED, or NO)
throws:
  MessagingException - if multipart creation failed
See Also:   MimeMessageHelper.setMimeMultiparts
See Also:   MimeMessageHelper.MULTIPART_MODE_NO
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED
See Also:   MimeMessageHelper.MULTIPART_MODE_RELATED
See Also:   MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED




getDefaultEncoding
protected String getDefaultEncoding(MimeMessage mimeMessage)(Code)
Determine the default encoding for the given MimeMessage.
Parameters:
  mimeMessage - the passed-in MimeMessage the default encoding associated with the MimeMessage,or null if none found



getDefaultFileTypeMap
protected FileTypeMap getDefaultFileTypeMap(MimeMessage mimeMessage)(Code)
Determine the default Java Activation FileTypeMap for the given MimeMessage.
Parameters:
  mimeMessage - the passed-in MimeMessage the default FileTypeMap associated with the MimeMessage,or a default ConfigurableMimeFileTypeMap if none found for the message
See Also:   ConfigurableMimeFileTypeMap



getEncoding
public String getEncoding()(Code)
Return the specific character encoding used for this message, if any.



getFileTypeMap
public FileTypeMap getFileTypeMap()(Code)
Return the FileTypeMap used by this MimeMessageHelper.



getMimeMessage
final public MimeMessage getMimeMessage()(Code)
Return the underlying MimeMessage object.



getMimeMultipart
final public MimeMultipart getMimeMultipart() throws IllegalStateException(Code)
Return the underlying MIME "multipart/related" object, if any. Can be used to manually add body parts, inline elements, etc.

This will be nested within the root MimeMultipart, in case of a multipart mail.
throws:
  IllegalStateException - if this helper is not in multipart mode
See Also:   MimeMessageHelper.isMultipart
See Also:   MimeMessageHelper.getRootMimeMultipart
See Also:   javax.mail.internet.MimeMultipart.addBodyPart




getRootMimeMultipart
final public MimeMultipart getRootMimeMultipart() throws IllegalStateException(Code)
Return the root MIME "multipart/mixed" object, if any. Can be used to manually add attachments.

This will be the direct content of the MimeMessage, in case of a multipart mail.
throws:
  IllegalStateException - if this helper is not in multipart mode
See Also:   MimeMessageHelper.isMultipart
See Also:   MimeMessageHelper.getMimeMessage
See Also:   javax.mail.internet.MimeMultipart.addBodyPart




isMultipart
final public boolean isMultipart()(Code)
Return whether this helper is in multipart mode, i.e. whether it holds a multipart message.
See Also:   MimeMessageHelper.MimeMessageHelper(MimeMessage,boolean)



isValidateAddresses
public boolean isValidateAddresses()(Code)
Return whether this helper will validate all addresses passed to it.



setBcc
public void setBcc(InternetAddress bcc) throws MessagingException(Code)



setBcc
public void setBcc(InternetAddress[] bcc) throws MessagingException(Code)



setBcc
public void setBcc(String bcc) throws MessagingException(Code)



setBcc
public void setBcc(String[] bcc) throws MessagingException(Code)



setCc
public void setCc(InternetAddress cc) throws MessagingException(Code)



setCc
public void setCc(InternetAddress[] cc) throws MessagingException(Code)



setCc
public void setCc(String cc) throws MessagingException(Code)



setCc
public void setCc(String[] cc) throws MessagingException(Code)



setFileTypeMap
public void setFileTypeMap(FileTypeMap fileTypeMap)(Code)
Set the Java Activation Framework FileTypeMap to use for determining the content type of inline content and attachments that get added to the message.

Default is the FileTypeMap that the underlying MimeMessage carries, if any, or the Activation Framework's default FileTypeMap instance else.
See Also:   MimeMessageHelper.addInline
See Also:   MimeMessageHelper.addAttachment
See Also:   MimeMessageHelper.getDefaultFileTypeMap(javax.mail.internet.MimeMessage)
See Also:   JavaMailSenderImpl.setDefaultFileTypeMap
See Also:   javax.activation.FileTypeMap.getDefaultFileTypeMap
See Also:   ConfigurableMimeFileTypeMap




setFrom
public void setFrom(InternetAddress from) throws MessagingException(Code)



setFrom
public void setFrom(String from) throws MessagingException(Code)



setFrom
public void setFrom(String from, String personal) throws MessagingException, UnsupportedEncodingException(Code)



setMimeMultiparts
final protected void setMimeMultiparts(MimeMultipart root, MimeMultipart main)(Code)
Set the given MimeMultipart objects for use by this MimeMessageHelper.
Parameters:
  root - the root MimeMultipart object, which attachments will be added to;or null to indicate no multipart at all
Parameters:
  main - the main MimeMultipart object, which text(s) and inline elementswill be added to (can be the same as the root multipart object, or an elementnested underneath the root multipart element)



setPriority
public void setPriority(int priority) throws MessagingException(Code)
Set the priority ("X-Priority" header) of the message.
Parameters:
  priority - the priority value;typically between 1 (highest) and 5 (lowest)
throws:
  MessagingException - in case of errors



setReplyTo
public void setReplyTo(InternetAddress replyTo) throws MessagingException(Code)



setReplyTo
public void setReplyTo(String replyTo) throws MessagingException(Code)



setReplyTo
public void setReplyTo(String replyTo, String personal) throws MessagingException, UnsupportedEncodingException(Code)



setSentDate
public void setSentDate(Date sentDate) throws MessagingException(Code)
Set the sent-date of the message.
Parameters:
  sentDate - the date to set (never null)
throws:
  MessagingException - in case of errors



setSubject
public void setSubject(String subject) throws MessagingException(Code)
Set the subject of the message, using the correct encoding.
Parameters:
  subject - the subject text
throws:
  MessagingException - in case of errors



setText
public void setText(String text) throws MessagingException(Code)
Set the given text directly as content in non-multipart mode or as default body part in multipart mode. Always applies the default content type "text/plain".

NOTE: Invoke MimeMessageHelper.addInline after setText; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  text - the text for the message
throws:
  MessagingException - in case of errors




setText
public void setText(String text, boolean html) throws MessagingException(Code)
Set the given text directly as content in non-multipart mode or as default body part in multipart mode. The "html" flag determines the content type to apply.

NOTE: Invoke MimeMessageHelper.addInline after setText; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  text - the text for the message
Parameters:
  html - whether to apply content type "text/html" for anHTML mail, using default content type ("text/plain") else
throws:
  MessagingException - in case of errors




setText
public void setText(String plainText, String htmlText) throws MessagingException(Code)
Set the given plain text and HTML text as alternatives, offering both options to the email client. Requires multipart mode.

NOTE: Invoke MimeMessageHelper.addInline after setText; else, mail readers might not be able to resolve inline references correctly.
Parameters:
  plainText - the plain text for the message
Parameters:
  htmlText - the HTML text for the message
throws:
  MessagingException - in case of errors




setTo
public void setTo(InternetAddress to) throws MessagingException(Code)



setTo
public void setTo(InternetAddress[] to) throws MessagingException(Code)



setTo
public void setTo(String to) throws MessagingException(Code)



setTo
public void setTo(String[] to) throws MessagingException(Code)



setValidateAddresses
public void setValidateAddresses(boolean validateAddresses)(Code)
Set whether to validate all addresses which get passed to this helper. Default is "false".

Note that this is by default just available for JavaMail >= 1.3. You can override the default validateAddress method for validation on older JavaMail versions (or for custom validation).
See Also:   MimeMessageHelper.validateAddress




validateAddress
protected void validateAddress(InternetAddress address) throws AddressException(Code)
Validate the given mail address. Called by all of MimeMessageHelper's address setters and adders.

Default implementation invokes InternetAddress.validate(), provided that address validation is activated for the helper instance.

Note that this method will just work on JavaMail >= 1.3. You can override it for validation on older JavaMail versions or for custom validation.
Parameters:
  address - the address to validate
throws:
  AddressException - if validation failed
See Also:   MimeMessageHelper.isValidateAddresses()
See Also:   javax.mail.internet.InternetAddress.validate




validateAddresses
protected void validateAddresses(InternetAddress[] addresses) throws AddressException(Code)
Validate all given mail addresses. Default implementation simply delegates to validateAddress for each address.
Parameters:
  addresses - the addresses to validate
throws:
  AddressException - if validation failed
See Also:   MimeMessageHelper.validateAddress(InternetAddress)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.