org.springframework.mail.javamail
Class JavaMailSenderImpl

java.lang.Object
  extended byorg.springframework.mail.javamail.JavaMailSenderImpl
All Implemented Interfaces:
JavaMailSender, MailSender

public class JavaMailSenderImpl
extends Object
implements JavaMailSender

Implementation of the JavaMailSender interface. Can also be used as plain MailSender implementation.

Allows for defining all settings locally as bean properties. Alternatively, a pre-configured JavaMail Session can be specified, possibly pulled from an application server's JNDI environment.

Non-default properties in this object will always override the settings in the JavaMail Session. Note that if overriding all values locally, there is no value in setting a pre-configured Session.

Since:
10.09.2003
Author:
Dmitriy Kopylenko, Juergen Hoeller
See Also:
JavaMailSender, MailSender

Field Summary
static int DEFAULT_PORT
           
static String DEFAULT_PROTOCOL
           
protected  Log logger
           
 
Constructor Summary
JavaMailSenderImpl()
           
 
Method Summary
 MimeMessage createMimeMessage()
          Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender.
 MimeMessage createMimeMessage(InputStream contentStream)
          Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender, using the given input stream as the message source.
 String getHost()
          Return the mail server host.
 String getPassword()
          Return the password for the account at the mail host.
 int getPort()
          Return the mail server port.
 String getProtocol()
          Return the mail protocol.
 Session getSession()
          Return the JavaMail Session.
protected  Transport getTransport(Session session)
          Get a Transport object for the given JavaMail Session.
 String getUsername()
          Return the username for the account at the mail host.
 void send(MimeMessage mimeMessage)
          Send the given JavaMail MIME message.
 void send(MimeMessage[] mimeMessages)
          Send the given array of JavaMail MIME messages in batch.
 void send(MimeMessage[] mimeMessages, Object[] originalMessages)
           
 void send(MimeMessagePreparator mimeMessagePreparator)
          Send the JavaMail MIME message prepared by the given MimeMessagePreparator.
 void send(MimeMessagePreparator[] mimeMessagePreparators)
          Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.
 void send(SimpleMailMessage simpleMessage)
          Send the given simple mail message.
 void send(SimpleMailMessage[] simpleMessages)
          Send the given array of simple mail messages in batch.
 void setHost(String host)
          Set the mail server host, typically an SMTP host.
 void setJavaMailProperties(Properties javaMailProperties)
          Set JavaMail properties for the Session.
 void setPassword(String password)
          Set the password for the account at the mail host, if any.
 void setPort(int port)
          Set the mail server port.
 void setProtocol(String protocol)
          Set the mail protocol.
 void setSession(Session session)
          Set the JavaMail Session, possibly pulled from JNDI.
 void setUsername(String username)
          Set the username for the account at the mail host, if any.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROTOCOL

public static final String DEFAULT_PROTOCOL
See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

logger

protected final Log logger
Constructor Detail

JavaMailSenderImpl

public JavaMailSenderImpl()
Method Detail

setJavaMailProperties

public void setJavaMailProperties(Properties javaMailProperties)
Set JavaMail properties for the Session. A new Session will be created with those properties. Use either this or setSession, not both.

Non-default properties in this MailSender will override given JavaMail properties.

See Also:
setSession(javax.mail.Session)

setSession

public void setSession(Session session)
Set the JavaMail Session, possibly pulled from JNDI. Default is a new Session without defaults, i.e. completely configured via this object's properties.

If using a pre-configured Session, non-default properties in this MailSender will override the settings in the Session.

See Also:
setJavaMailProperties(java.util.Properties)

getSession

public Session getSession()
Return the JavaMail Session.


setProtocol

public void setProtocol(String protocol)
Set the mail protocol. Default is SMTP.


getProtocol

public String getProtocol()
Return the mail protocol.


setHost

public void setHost(String host)
Set the mail server host, typically an SMTP host.


getHost

public String getHost()
Return the mail server host.


setPort

public void setPort(int port)
Set the mail server port. Default is -1, letting JavaMail use the default SMTP port (25).


getPort

public int getPort()
Return the mail server port.


setUsername

public void setUsername(String username)
Set the username for the account at the mail host, if any.


getUsername

public String getUsername()
Return the username for the account at the mail host.


setPassword

public void setPassword(String password)
Set the password for the account at the mail host, if any.


getPassword

public String getPassword()
Return the password for the account at the mail host.


send

public void send(SimpleMailMessage simpleMessage)
          throws MailException
Description copied from interface: MailSender
Send the given simple mail message.

Specified by:
send in interface MailSender
Parameters:
simpleMessage - the message to send
Throws:
MailException

send

public void send(SimpleMailMessage[] simpleMessages)
          throws MailException
Description copied from interface: MailSender
Send the given array of simple mail messages in batch.

Specified by:
send in interface MailSender
Parameters:
simpleMessages - the messages to send
Throws:
MailException

createMimeMessage

public MimeMessage createMimeMessage()
Description copied from interface: JavaMailSender
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).

Specified by:
createMimeMessage in interface JavaMailSender
Returns:
the new MimeMessage instance
See Also:
JavaMailSender.send(MimeMessage), JavaMailSender.send(MimeMessage[])

createMimeMessage

public MimeMessage createMimeMessage(InputStream contentStream)
                              throws MailException
Description copied from interface: JavaMailSender
Create a new JavaMail MimeMessage for the underlying JavaMail Session of this sender, using the given input stream as the message source.

Specified by:
createMimeMessage in interface JavaMailSender
Parameters:
contentStream - the raw MIME input stream for the message
Returns:
the new MimeMessage instance
Throws:
MailException

send

public void send(MimeMessage mimeMessage)
          throws MailException
Description copied from interface: JavaMailSender
Send the given JavaMail MIME message. The message needs to have been created with createMimeMessage.

Specified by:
send in interface JavaMailSender
Parameters:
mimeMessage - message to send
Throws:
MailException
See Also:
JavaMailSender.createMimeMessage()

send

public void send(MimeMessage[] mimeMessages)
          throws MailException
Description copied from interface: JavaMailSender
Send the given array of JavaMail MIME messages in batch. The messages need to have been created with createMimeMessage.

Specified by:
send in interface JavaMailSender
Parameters:
mimeMessages - messages to send
Throws:
MailException
See Also:
JavaMailSender.createMimeMessage()

send

public void send(MimeMessage[] mimeMessages,
                 Object[] originalMessages)
          throws MailException
Throws:
MailException

send

public void send(MimeMessagePreparator mimeMessagePreparator)
          throws MailException
Description copied from interface: JavaMailSender
Send the JavaMail MIME message prepared by the given MimeMessagePreparator. Alternative way to prepare MimeMessage instances, instead of createMimeMessage and send(MimeMessage) calls. Takes care of proper exception conversion.

Specified by:
send in interface JavaMailSender
Parameters:
mimeMessagePreparator - the preparator to use
Throws:
MailException

send

public void send(MimeMessagePreparator[] mimeMessagePreparators)
          throws MailException
Description copied from interface: JavaMailSender
Send the JavaMail MIME messages prepared by the given MimeMessagePreparators. Alternative way to prepare MimeMessage instances, instead of createMimeMessage and send(MimeMessage[]) calls. Takes care of proper exception conversion.

Specified by:
send in interface JavaMailSender
Parameters:
mimeMessagePreparators - the preparator to use
Throws:
MailException

getTransport

protected Transport getTransport(Session session)
                          throws NoSuchProviderException
Get a Transport object for the given JavaMail Session. Can be overridden in subclasses, e.g. to return a mock Transport object.

Throws:
NoSuchProviderException


Copyright (C) 2003-2004 The Spring Framework Project.