|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.codemonkey.simplejavamail.MailSession
class MailSession
Creates and initializes a Session instance based on provided host and credentials as well as a TransportStrategy instance
to apply SMTP, SMTPS or SMTP + TLS protocol semantics.
The Session needs to be created before assembling the concerning e-mail message in the Mailer as the Sun JavaMail
API directly wires the e-mail message into the Session. The session again is needed when actually sending the e-mail or when
toString() is called.
| Field Summary | |
|---|---|
private Session |
session
Used to actually send the email. |
private TransportStrategy |
transportStrategy
The transport protocol strategy enum that actually handles the session configuration. |
| Constructor Summary | |
|---|---|
MailSession(Session session)
Default constructor, stores the given mail session for later use. |
|
MailSession(String host,
int port,
String username,
String password,
TransportStrategy transportStrategy)
Overloaded constructor which produces a new Session on the fly. |
|
| Method Summary | |
|---|---|
Session |
createMailSession(String host,
int port,
String username,
String password)
Actually instantiates and configures the Session instance. |
Session |
getSession()
Bean getter for session. |
void |
sendMessage(Message message)
Sends a Sun JavaMail Message object using the Session#getTransport(). |
String |
toString()
Returns host details, credentials used and whether authentication will take place and finally the transport protocol used. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private final Session session
MailSession directly, when no Session instance was provided.
MailSession(Session),
MailSession(String, int, String, String, TransportStrategy)private TransportStrategy transportStrategy
| Constructor Detail |
|---|
public MailSession(Session session)
session - A preconfigured mail Session object with which a Message can be produced.
public MailSession(String host,
int port,
String username,
String password,
TransportStrategy transportStrategy)
Session on the fly. Use this if you don't have a mail session configured in your
web container, or Spring context etc.
host - The address URL of the SMTP server to be used.port - The port of the SMTP server.username - An optional username, may be null.password - An optional password, may be null, but only if username is null as well.| Method Detail |
|---|
public Session createMailSession(String host,
int port,
String username,
String password)
Session instance. Delegates resolving transport protocol specific properties to the
transportStrategy in two ways:
host - The address URL of the SMTP server to be used.port - The port of the SMTP server.username - An optional username, may be null.password - An optional password, may be null.
Session instance complete with transport protocol settings.TransportStrategy.generateProperties(),
TransportStrategy.propertyNameHost(),
TransportStrategy.propertyNamePort(),
TransportStrategy.propertyNameUsername(),
TransportStrategy.propertyNameAuthenticate()
public void sendMessage(Message message)
throws MessagingException
Message object using the Session#getTransport(). It will call Transport#connect()
assuming all connection details have been configured in the provided Session instance.
Performs a call to Message#saveChanges() as the Sun JavaMail API indicates it is needed to configure the message headers and
providing a message id.
message - The message to send. Generate by the Mailer.
MessagingException - Thrown by Message#saveChanges(), Transport#connect(),
Transport#sendMessage(Message, javax.mail.Address[]), Transport#close()public String toString()
toString in class Objectpublic Session getSession()
session.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||