net.sf.sasl.common.communication.mail
Class SimpleMailChannel

java.lang.Object
  extended by net.sf.sasl.common.communication.mail.SimpleMailChannel
All Implemented Interfaces:
ICommunicationChannel

public class SimpleMailChannel
extends Object
implements ICommunicationChannel

The class implements a simple e-Mail communication channel, for which the sender and receivers are hard wired during creation of the channel. The input of the sendOverChannel method will be converted to a MIME message and delivered to the receivers via a SMTP server.
The setter methods of the class should not be called in a multi threading way, otherwise the behavior of the sendOverChannel method gets undefined.
Default property values:
smtpHostname = localhost
smtpPort = 25
smtpUser = null (no authentication required)
smtpPassword = null (no authentication required)
mimeType = text/plain

Since:
0.0.1 (sasl-common-aspect-library)
Author:
Philipp Förmer

Constructor Summary
SimpleMailChannel()
          Default constructor, does nothing actually.
 
Method Summary
 String getMimeType()
          Returns the mime type of the e-Mail messages which will be send over this object.
 List<javax.mail.internet.InternetAddress> getReceiverAddressList()
          Returns a list of receiver addresses to which e-Mail messages should be delivered which were send over this object.
 javax.mail.internet.InternetAddress getSenderAddress()
          Returns the sender address which sends e-Mail messages over this object (From-part of an e-Mail message).
 String getSmtpHostname()
          Returns the SMTP server hostname which should deliver e-Mail messages, which will be sended over this object.
 String getSmtpPassword()
          Returns the password of the SMTP user which will be used to authenticate the SMTP user at the SMTP server, if authentication is required for sending e-Mail messages.
 int getSmtpPort()
          Returns the port over which the SMTP server accepts incoming e-Mail messages.
 String getSmtpUser()
          Returns the name of the SMTP user which will be used to authenticate at the SMTP server, if authentication is required.
 void sendOverChannel(String subject, String message)
          Tries to send an e-Mail message with subject "subject" and e-Mail message "message" to the configured list of receiver addresses over the setted SMTP server "synchronously" (=call blocks until the SMTP server sends an answer).
 void setMimeType(String mimeType)
          Sets the mime type of the e-Mail messages which will be send over this object.
 void setReceiverAddressList(List<javax.mail.internet.InternetAddress> receiverAddressList)
          Sets a list of receiver addresses to which e-Mail messages should be delivered which were send over this object.
 void setSenderAddress(javax.mail.internet.InternetAddress senderAddress)
          Sets the sender address which sends e-Mail messages over this object (From-part of an e-Mail message).
 void setSmtpHostname(String smtpHostname)
          Sets the SMTP server hostname which should deliver e-Mail messages, which will be sended over this object.
 void setSmtpPassword(String smtpPassword)
          Sets the password of the SMTP user which will be used to authenticate the SMTP user at the SMTP server, if authentication is required for sending e-Mail messages.
 void setSmtpPort(int smtpPort)
          Sets the port over which the SMTP server accepts incoming e-Mail messages.
 void setSmtpUser(String smtpUser)
          Sets the name of the SMTP user which will be used to authenticate at the SMTP server, if authentication is required.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleMailChannel

public SimpleMailChannel()
Default constructor, does nothing actually.

Since:
0.0.1 (sasl-common-aspect-library)
Method Detail

getSmtpHostname

public String getSmtpHostname()
Returns the SMTP server hostname which should deliver e-Mail messages, which will be sended over this object.

Returns:
non null string
Since:
0.0.1 (sasl-common-aspect-library)

setSmtpHostname

public void setSmtpHostname(String smtpHostname)
                     throws IllegalArgumentException
Sets the SMTP server hostname which should deliver e-Mail messages, which will be sended over this object.

Parameters:
smtpHost -
Throws:
IllegalArgumentException - if smtpHostname is empty.
Since:
0.0.1 (sasl-common-aspect-library)

getSmtpPort

public int getSmtpPort()
Returns the port over which the SMTP server accepts incoming e-Mail messages.

Returns:
Since:
0.0.1 (sasl-common-aspect-library)

setSmtpPort

public void setSmtpPort(int smtpPort)
                 throws IllegalArgumentException
Sets the port over which the SMTP server accepts incoming e-Mail messages.

Parameters:
smtpPort - integer value greater than 0.
Throws:
IllegalArgumentException - if smtpPort is lesser than 1.
Since:
0.0.1 (sasl-common-aspect-library)

getSmtpUser

public String getSmtpUser()
Returns the name of the SMTP user which will be used to authenticate at the SMTP server, if authentication is required.

Returns:
null or non null string.
Since:
0.0.1 (sasl-common-aspect-library)

setSmtpUser

public void setSmtpUser(String smtpUser)
Sets the name of the SMTP user which will be used to authenticate at the SMTP server, if authentication is required.

Parameters:
smtpUser - null or non null
Since:
0.0.1 (sasl-common-aspect-library)

getSmtpPassword

public String getSmtpPassword()
Returns the password of the SMTP user which will be used to authenticate the SMTP user at the SMTP server, if authentication is required for sending e-Mail messages.

Returns:
null or non null string
Since:
0.0.1 (sasl-common-aspect-library)

setSmtpPassword

public void setSmtpPassword(String smtpPassword)
Sets the password of the SMTP user which will be used to authenticate the SMTP user at the SMTP server, if authentication is required for sending e-Mail messages.

Parameters:
smtpPassword - null or non null string
Since:
0.0.1 (sasl-common-aspect-library)

getMimeType

public String getMimeType()
Returns the mime type of the e-Mail messages which will be send over this object.

Returns:
non null string
Since:
0.0.1 (sasl-common-aspect-library)

setMimeType

public void setMimeType(String mimeType)
                 throws IllegalArgumentException
Sets the mime type of the e-Mail messages which will be send over this object.

Parameters:
mimeType - non empty string
Throws:
IllegalArgumentException - if mimeType is empty.
Since:
0.0.1 (sasl-common-aspect-library)

getSenderAddress

public javax.mail.internet.InternetAddress getSenderAddress()
Returns the sender address which sends e-Mail messages over this object (From-part of an e-Mail message).

Returns:
null or non null
Since:
0.0.1 (sasl-common-aspect-library)

setSenderAddress

public void setSenderAddress(javax.mail.internet.InternetAddress senderAddress)
Sets the sender address which sends e-Mail messages over this object (From-part of an e-Mail message).

Parameters:
sender - null or non null
Since:
0.0.1 (sasl-common-aspect-library)

getReceiverAddressList

public List<javax.mail.internet.InternetAddress> getReceiverAddressList()
Returns a list of receiver addresses to which e-Mail messages should be delivered which were send over this object.

Returns:
non null list
Since:
0.0.1 (sasl-common-aspect-library)

setReceiverAddressList

public void setReceiverAddressList(List<javax.mail.internet.InternetAddress> receiverAddressList)
                            throws IllegalArgumentException
Sets a list of receiver addresses to which e-Mail messages should be delivered which were send over this object. Null values in the list will be ignored.

Parameters:
receiverList - non null list
Throws:
IllegalArgumentException - if receiverList is empty.
Since:
0.0.1 (sasl-common-aspect-library)

sendOverChannel

public void sendOverChannel(String subject,
                            String message)
                     throws IllegalArgumentException,
                            CommunicationChannelException
Tries to send an e-Mail message with subject "subject" and e-Mail message "message" to the configured list of receiver addresses over the setted SMTP server "synchronously" (=call blocks until the SMTP server sends an answer). The from part of the e-Mail will be the setted senderAddress. If the senderAddress is null, than the return value from InternetAddress.getLocalAddress(Session) will be used as the sender address. In all cases where no special javax.mail property files are configured the return value from that procedure will be: user.name AT default hostname.

Specified by:
sendOverChannel in interface ICommunicationChannel
Parameters:
subject - non null subject of the message.
message - non null message.
Throws:
IllegalArgumentException - if subject or message are null
CommunicationChannelException - if an error occured by trying to send the e-Mail message to the SMTP server.
Since:
0.0.1 (sasl-common-aspect-library)
See Also:
ICommunicationChannel.sendOverChannel(java.lang.String, java.lang.String)


Copyright © 2010. All Rights Reserved.