| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
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. Also offers support for typical mail attachments. Advanced settings can still be applied directly to underlying MimeMessage!
Typically used in MimeMessagePreparator implementations or JavaMailSender client code: simply instantiating it as a facade to a MimeMessage, invoking setters on the facade, 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("me@mail.com");
message.setTo("you@mail.com");
message.setSubject("my subject");
message.setText("my text");
message.addAttachment("logo.gif", new ClassPathResource("images/mylogo.gif"));
}
});
| Constructor Summary | |
MimeMessageHelper(MimeMessage mimeMessage)Create new MimeMessageHelper for the given MimeMessage, assuming a simple text message (no multipart content). | |
MimeMessageHelper(MimeMessage mimeMessage, boolean multipart)Create new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting attachments) if requested. | |
| Method Summary | |
void | addAttachment(String attachmentFilename, File file)Add an attachment to the given MimeMessage, taking the content from a java.io.File. |
void | addAttachment(String attachmentFilename, InputStreamSource inputStreamSource)Add an attachment to the given MimeMessage, taking the content from an org.springframework.core.InputStreamResource. |
void | addAttachment(String attachmentFilename, DataSource dataSource)Add an attachment to the given MimeMessage, taking the content from a javax.activation.DataSource. |
MimeMessage | getMimeMessage()Return the underlying MimeMessage. |
void | setBcc(String bcc) |
void | setBcc(String[] bcc) |
void | setCc(String cc) |
void | setCc(String[] cc) |
void | setFrom(String from) |
void | setSubject(String subject) |
void | setText(String text) |
void | setText(String text, boolean html)Sets the given text directly as content in non-multipart mode respectively as default body part in multipart mode. |
void | setTo(String to) |
void | setTo(String[] to) |
| Constructor Detail |
public MimeMessageHelper(MimeMessage mimeMessage)
public MimeMessageHelper(MimeMessage mimeMessage, boolean multipart)
throws MessagingException
| Method Detail |
public void addAttachment(String attachmentFilename, File file)
throws 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)!
public void addAttachment(String attachmentFilename, InputStreamSource inputStreamSource)
throws 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.
public void addAttachment(String attachmentFilename, DataSource dataSource)
throws 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.
javax.activation.DataSource to take
the content from, determining the InputStream and the content typepublic MimeMessage getMimeMessage()
public void setBcc(String bcc)
throws MessagingException
public void setBcc(String[] bcc)
throws MessagingException
public void setCc(String cc)
throws MessagingException
public void setCc(String[] cc)
throws MessagingException
public void setFrom(String from)
throws MessagingException
public void setSubject(String subject)
throws MessagingException
public void setText(String text)
throws MessagingException
public void setText(String text, boolean html)
throws MessagingException
public void setTo(String to)
throws MessagingException
public void setTo(String[] to)
throws MessagingException
| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||