接口 JavaMailSender
- 所有超级接口:
MailSender
- 所有已知实现类:
JavaMailSenderImpl
public interface JavaMailSender extends MailSender
ExtendedMailSenderinterface for JavaMail, supporting MIME messages both as direct arguments and through preparation callbacks. Typically used in conjunction with theMimeMessageHelperclass for convenient creation of JavaMailMimeMessages, including attachments etc.Clients should talk to the mail sender through this interface if they need mail functionality beyond
SimpleMailMessage. The production implementation isJavaMailSenderImpl; for testing, mocks can be created based on this interface. Clients will typically receive the JavaMailSender reference through dependency injection.The recommended way of using this interface is the
MimeMessagePreparatormechanism, possibly using aMimeMessageHelperfor populating the message. SeeMimeMessageHelper's javadocfor an example.The entire JavaMail
Sessionmanagement is abstracted by the JavaMailSender. Client code should not deal with a Session in any way, rather leave the entire JavaMail configuration and resource handling to the JavaMailSender implementation. This also increases testability.A JavaMailSender client is not as easy to test as a plain
MailSenderclient, but still straightforward compared to traditional JavaMail code: Just letcreateMimeMessage()return a plainMimeMessagecreated with aSession.getInstance(new Properties())call, and check the passed-in messages in your mock implementations of the varioussendmethods.- 从以下版本开始:
- 07.10.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
MimeMessage,Session,JavaMailSenderImpl,MimeMessagePreparator,MimeMessageHelper
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 MimeMessagecreateMimeMessage()Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender.MimeMessagecreateMimeMessage(InputStream contentStream)Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender, using the given input stream as the message source.voidsend(MimeMessage mimeMessage)Send the given JavaMail MIME message.voidsend(MimeMessage... mimeMessages)Send the given array of JavaMail MIME messages in batch.voidsend(MimeMessagePreparator mimeMessagePreparator)Send the JavaMail MIME message prepared by the given MimeMessagePreparator.voidsend(MimeMessagePreparator... mimeMessagePreparators)Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.从接口继承的方法 org.springframework.mail.MailSender
send, send
方法详细资料
createMimeMessage
MimeMessage createMimeMessage()
Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender. Needs to be called to create MimeMessage instances that can be prepared by the client and passed to send(MimeMessage).- 返回:
- the new MimeMessage instance
- 另请参阅:
send(MimeMessage),send(MimeMessage[])
createMimeMessage
MimeMessage createMimeMessage(InputStream contentStream) throws MailException
Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender, using the given input stream as the message source.- 参数:
contentStream- the raw MIME input stream for the message- 返回:
- the new MimeMessage instance
- 抛出:
MailParseException- in case of message creation failureMailException
send
void send(MimeMessage mimeMessage) throws MailException
Send the given JavaMail MIME message. The message needs to have been created withcreateMimeMessage().- 参数:
mimeMessage- message to send- 抛出:
MailAuthenticationException- in case of authentication failureMailSendException- in case of failure when sending the messageMailException- 另请参阅:
createMimeMessage()
send
void send(MimeMessage... mimeMessages) throws MailException
Send the given array of JavaMail MIME messages in batch. The messages need to have been created withcreateMimeMessage().- 参数:
mimeMessages- messages to send- 抛出:
MailAuthenticationException- in case of authentication failureMailSendException- in case of failure when sending a messageMailException- 另请参阅:
createMimeMessage()
send
void send(MimeMessagePreparator mimeMessagePreparator) throws MailException
Send the JavaMail MIME message prepared by the given MimeMessagePreparator.Alternative way to prepare MimeMessage instances, instead of
createMimeMessage()andsend(MimeMessage)calls. Takes care of proper exception conversion.- 参数:
mimeMessagePreparator- the preparator to use- 抛出:
MailPreparationException- in case of failure when preparing the messageMailParseException- in case of failure when parsing the messageMailAuthenticationException- in case of authentication failureMailSendException- in case of failure when sending the messageMailException
send
void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException
Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.Alternative way to prepare MimeMessage instances, instead of
createMimeMessage()andsend(MimeMessage[])calls. Takes care of proper exception conversion.- 参数:
mimeMessagePreparators- the preparator to use- 抛出:
MailPreparationException- in case of failure when preparing a messageMailParseException- in case of failure when parsing a messageMailAuthenticationException- in case of authentication failureMailSendException- in case of failure when sending a messageMailException