|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.mail.javamail.MimeMessageHelper
Helper class for easy population of a javax.mail.internet.MimeMessage
.
Mirrors the simple setters of SimpleMailMessage, directly applying the values to the underlying MimeMessage. Allows to define a character encoding for the entire message, automatically applied by all methods of this helper.
Also offers support for typical mail attachments, and for personal names that accompany mail addresses. Note that advanced settings can still be applied directly to underlying MimeMessage!
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:
mailSender.send(new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws MessagingException {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);
message.setFrom("[email protected]");
message.setTo("[email protected]");
message.setSubject("my subject");
message.setText("my text");
message.addAttachment("logo.gif", new ClassPathResource("images/mylogo.gif"));
}
});
MimeMessage
,
getMimeMessage()
,
MimeMessagePreparator
,
JavaMailSender
,
JavaMailSenderImpl
,
SimpleMailMessage
Constructor Summary | |
MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage)
Create new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content). |
|
MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage,
boolean multipart)
Create new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting attachments) if requested. |
|
MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage,
boolean multipart,
java.lang.String encoding)
Create new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting attachments) if requested. |
|
MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage,
java.lang.String encoding)
Create new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content). |
Method Summary | |
void |
addAttachment(java.lang.String attachmentFilename,
javax.activation.DataSource dataSource)
Add an attachment to the given MimeMessage, taking the content from a javax.activation.DataSource . |
void |
addAttachment(java.lang.String attachmentFilename,
java.io.File file)
Add an attachment to the given MimeMessage, taking the content from a java.io.File. |
void |
addAttachment(java.lang.String attachmentFilename,
InputStreamSource inputStreamSource)
Add an attachment to the given MimeMessage, taking the content from an org.springframework.core.InputStreamResource. |
void |
addBcc(javax.mail.internet.InternetAddress bcc)
|
void |
addBcc(java.lang.String bcc)
|
void |
addBcc(java.lang.String bcc,
java.lang.String personal)
|
void |
addCc(javax.mail.internet.InternetAddress cc)
|
void |
addCc(java.lang.String cc)
|
void |
addCc(java.lang.String cc,
java.lang.String personal)
|
void |
addTo(javax.mail.internet.InternetAddress to)
|
void |
addTo(java.lang.String to)
|
void |
addTo(java.lang.String to,
java.lang.String personal)
|
java.lang.String |
getEncoding()
Return the character encoding used for this message. |
javax.mail.internet.MimeMessage |
getMimeMessage()
Return the underlying MimeMessage. |
void |
setBcc(javax.mail.internet.InternetAddress bcc)
|
void |
setBcc(javax.mail.internet.InternetAddress[] bcc)
|
void |
setBcc(java.lang.String bcc)
|
void |
setBcc(java.lang.String[] bcc)
|
void |
setCc(javax.mail.internet.InternetAddress cc)
|
void |
setCc(javax.mail.internet.InternetAddress[] cc)
|
void |
setCc(java.lang.String cc)
|
void |
setCc(java.lang.String[] cc)
|
void |
setFrom(javax.mail.internet.InternetAddress from)
|
void |
setFrom(java.lang.String from)
|
void |
setFrom(java.lang.String from,
java.lang.String personal)
|
void |
setSubject(java.lang.String subject)
|
void |
setText(java.lang.String text)
|
void |
setText(java.lang.String text,
boolean html)
Set the given text directly as content in non-multipart mode respectively as default body part in multipart mode. |
void |
setTo(javax.mail.internet.InternetAddress to)
|
void |
setTo(javax.mail.internet.InternetAddress[] to)
|
void |
setTo(java.lang.String to)
|
void |
setTo(java.lang.String[] to)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage)
mimeMessage
- MimeMessage to work onMimeMessageHelper(javax.mail.internet.MimeMessage, boolean)
public MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage, boolean multipart) throws javax.mail.MessagingException
mimeMessage
- MimeMessage to work onmultipart
- whether to create a multipart message that
supports attachmentspublic MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage, java.lang.String encoding)
mimeMessage
- MimeMessage to work onencoding
- the character encoding to use for the messageMimeMessageHelper(javax.mail.internet.MimeMessage, boolean)
public MimeMessageHelper(javax.mail.internet.MimeMessage mimeMessage, boolean multipart, java.lang.String encoding) throws javax.mail.MessagingException
mimeMessage
- MimeMessage to work onmultipart
- whether to create a multipart message that
supports attachmentsencoding
- the character encoding to use for the messageMethod Detail |
public javax.mail.internet.MimeMessage getMimeMessage()
public java.lang.String getEncoding()
public void setFrom(javax.mail.internet.InternetAddress from) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setFrom(java.lang.String from) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setFrom(java.lang.String from, java.lang.String personal) throws javax.mail.MessagingException, java.io.UnsupportedEncodingException
javax.mail.MessagingException
java.io.UnsupportedEncodingException
public void setTo(javax.mail.internet.InternetAddress to) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setTo(javax.mail.internet.InternetAddress[] to) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setTo(java.lang.String to) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setTo(java.lang.String[] to) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addTo(javax.mail.internet.InternetAddress to) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addTo(java.lang.String to) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addTo(java.lang.String to, java.lang.String personal) throws javax.mail.MessagingException, java.io.UnsupportedEncodingException
javax.mail.MessagingException
java.io.UnsupportedEncodingException
public void setCc(javax.mail.internet.InternetAddress cc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setCc(javax.mail.internet.InternetAddress[] cc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setCc(java.lang.String cc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setCc(java.lang.String[] cc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addCc(javax.mail.internet.InternetAddress cc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addCc(java.lang.String cc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addCc(java.lang.String cc, java.lang.String personal) throws javax.mail.MessagingException, java.io.UnsupportedEncodingException
javax.mail.MessagingException
java.io.UnsupportedEncodingException
public void setBcc(javax.mail.internet.InternetAddress bcc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setBcc(javax.mail.internet.InternetAddress[] bcc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setBcc(java.lang.String bcc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setBcc(java.lang.String[] bcc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addBcc(javax.mail.internet.InternetAddress bcc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addBcc(java.lang.String bcc) throws javax.mail.MessagingException
javax.mail.MessagingException
public void addBcc(java.lang.String bcc, java.lang.String personal) throws javax.mail.MessagingException, java.io.UnsupportedEncodingException
javax.mail.MessagingException
java.io.UnsupportedEncodingException
public void setSubject(java.lang.String subject) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setText(java.lang.String text) throws javax.mail.MessagingException
javax.mail.MessagingException
public void setText(java.lang.String text, boolean html) throws javax.mail.MessagingException
text
- text to sethtml
- whether to apply content type "text/html" for an
HTML mail, using default content type ("text/plain") else
javax.mail.MessagingException
public void addAttachment(java.lang.String attachmentFilename, java.io.File file) throws javax.mail.MessagingException
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)!
attachmentFilename
- the name of the attachment as it will
appear in the mailfile
- the File resource to take the content from
javax.mail.MessagingException
addAttachment(String, org.springframework.core.io.InputStreamSource)
,
addAttachment(String, javax.activation.DataSource)
public void addAttachment(java.lang.String attachmentFilename, InputStreamSource inputStreamSource) throws javax.mail.MessagingException
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.
attachmentFilename
- the name of the attachment as it will
appear in the mailinputStreamSource
- the resource to take the content from
javax.mail.MessagingException
addAttachment(String, File)
,
addAttachment(String, javax.activation.DataSource)
public void addAttachment(java.lang.String attachmentFilename, javax.activation.DataSource dataSource) throws javax.mail.MessagingException
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.
attachmentFilename
- the name of the attachment as it will
appear in the mail (the content type will be determined by this)dataSource
- the javax.activation.DataSource
to take
the content from, determining the InputStream and the content type
javax.mail.MessagingException
- in case of errorsaddAttachment(String, File)
,
addAttachment(String, org.springframework.core.io.InputStreamSource)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |