util
Class Mailer

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.Mailer
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying
Direct Known Subclasses:
Calima, OffLimitMailer, TargetReport

public class Mailer
extends PropertyBundles

Used to create a e-mail transport session out of PropertyBearing.


Nested Class Summary
static class Mailer.Google
          Send a test message via my google account.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  boolean debug
          A debug flag, acts globally.
static String KEY_DEBUG
          If true, messages are not sent.
static String KEY_PASSWORD
          Given together with a username, we use password authentication.
static String KEY_SMTPHOST
          Key pointing to the smtp server.
static String KEY_SMTPPORT
          Key pointing to the smtp server port.
static String KEY_USERNAME
          Given together with a password, we use password authentication.
static String KEY_USESSL
          If true, we use SSL.
private static String MAILAUTH
          The key for authentication use.
private  javax.mail.Session mailer
          The mailer used internally.
private static String MAILSAUTH
          The key for authentication use.
private static String MAILSMTPHOST
          The key in the smtp-session key denoting the host for JavaMail.
private static String MAILSMTPPORT
          The key for authentication use.
private static String MAILSMTPSHOST
          The key in the smtp-session key denoting the host for JavaMail.
static String STELLAMAINTENANCE
          A generic user receiving maintenance mails from STELLA.
static String STELLAROBOTIC
          A generic user receiving maintenance mails from STELLA.
private  com.sun.mail.smtp.SMTPTransport transport
          The transporter.
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
applet, DEFURLUSECONFIG, DEFURLUSECURRENT, DEFURLUSEHOME, KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
Mailer(Map<String,String> prop)
          Subclasses that directly want to create their mailer may use this constructor.
 
Method Summary
 void close()
           
private  boolean createMailSession()
          We create our private mailer session out of the properties.
private  javax.mail.Session createMailSession(PropertySupplying i)
          Creates a mailer session out of some properties.
static Mailer createStellaRoboticMailer()
          Factory method to create a mailer for the robotic account on Google
private  com.sun.mail.smtp.SMTPTransport createTransport(javax.mail.Session s, boolean usessl)
          Creates the transport agent for the send-mail protocol.
static javax.mail.Address[] getAddresses(String comma)
          Converts a comma-separated list of RFC-822 formatted mail addresses into an array of internet addresses.
static javax.mail.Address getStellaMaintenance()
          Creates a useable e-mail address for the stella maintenance user.
static javax.mail.Address getStellaRobotic()
          Creates a useable e-mail address for the stella maintenance user.
 void init()
          We prepare the session for sending mail.
 javax.mail.internet.MimeMessage prepareMail(javax.mail.Address from, javax.mail.Address[] to, javax.mail.Address[] cc, javax.mail.Address[] bcc, String subject, String text, Date time)
          Prepares a mail for the given session.
 boolean sendMail(javax.mail.internet.MimeMessage errmail)
          Truly sends a previously prepared mail.
 boolean sendMail(javax.mail.internet.MimeMessage errmail, boolean debug)
          Sends a previously prepared mail or debugs.
 Thread threadMail(javax.mail.internet.MimeMessage errmail, boolean debug)
          Sends a previously prepared mail or debugs.
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, loadAppletResource, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_SMTPHOST

public static final String KEY_SMTPHOST
Key pointing to the smtp server.

See Also:
Constant Field Values

KEY_SMTPPORT

public static final String KEY_SMTPPORT
Key pointing to the smtp server port.

See Also:
Constant Field Values

KEY_USESSL

public static final String KEY_USESSL
If true, we use SSL.

See Also:
Constant Field Values

KEY_USERNAME

public static final String KEY_USERNAME
Given together with a password, we use password authentication.

See Also:
Constant Field Values

KEY_PASSWORD

public static final String KEY_PASSWORD
Given together with a username, we use password authentication.

See Also:
Constant Field Values

KEY_DEBUG

public static final String KEY_DEBUG
If true, messages are not sent.

See Also:
Constant Field Values

STELLAROBOTIC

public static final String STELLAROBOTIC
A generic user receiving maintenance mails from STELLA.

See Also:
Constant Field Values

STELLAMAINTENANCE

public static final String STELLAMAINTENANCE
A generic user receiving maintenance mails from STELLA.

See Also:
Constant Field Values

MAILSMTPSHOST

private static final String MAILSMTPSHOST
The key in the smtp-session key denoting the host for JavaMail.

See Also:
Constant Field Values

MAILSAUTH

private static final String MAILSAUTH
The key for authentication use.

See Also:
Constant Field Values

MAILSMTPHOST

private static final String MAILSMTPHOST
The key in the smtp-session key denoting the host for JavaMail.

See Also:
Constant Field Values

MAILAUTH

private static final String MAILAUTH
The key for authentication use.

See Also:
Constant Field Values

MAILSMTPPORT

private static final String MAILSMTPPORT
The key for authentication use.

See Also:
Constant Field Values

mailer

private javax.mail.Session mailer
The mailer used internally.


transport

private com.sun.mail.smtp.SMTPTransport transport
The transporter.


debug

private boolean debug
A debug flag, acts globally. Can be overridn by direct invoke of sendMail(MimeMessage,boolean).

Constructor Detail

Mailer

public Mailer(Map<String,String> prop)
Subclasses that directly want to create their mailer may use this constructor.

Method Detail

init

public void init()
We prepare the session for sending mail.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

createMailSession

private boolean createMailSession()
We create our private mailer session out of the properties. Subclasses may call this method from their init.


createMailSession

private javax.mail.Session createMailSession(PropertySupplying i)
Creates a mailer session out of some properties.


createTransport

private com.sun.mail.smtp.SMTPTransport createTransport(javax.mail.Session s,
                                                        boolean usessl)
Creates the transport agent for the send-mail protocol. Either uses SSL-encription or normal protocol.

Parameters:
s - The Session, also created with SSL usage
usessl - True, if smtps should be used as transport protocol.
Returns:
The mail transport agent or null if no such provider exists.

getAddresses

public static final javax.mail.Address[] getAddresses(String comma)
                                               throws javax.mail.internet.AddressException
Converts a comma-separated list of RFC-822 formatted mail addresses into an array of internet addresses. The RFC-822 enforcement is not too strict, in a way that e.g. even mail addresses giving just the user name without a domain are valid.

Throws:
javax.mail.internet.AddressException

getStellaMaintenance

public static javax.mail.Address getStellaMaintenance()
Creates a useable e-mail address for the stella maintenance user.


getStellaRobotic

public static javax.mail.Address getStellaRobotic()
Creates a useable e-mail address for the stella maintenance user.


prepareMail

public javax.mail.internet.MimeMessage prepareMail(javax.mail.Address from,
                                                   javax.mail.Address[] to,
                                                   javax.mail.Address[] cc,
                                                   javax.mail.Address[] bcc,
                                                   String subject,
                                                   String text,
                                                   Date time)
Prepares a mail for the given session.


sendMail

public boolean sendMail(javax.mail.internet.MimeMessage errmail)
Truly sends a previously prepared mail.


sendMail

public boolean sendMail(javax.mail.internet.MimeMessage errmail,
                        boolean debug)
Sends a previously prepared mail or debugs. Fascinating enough this does not need a mail session anymore, everything is already packed into the mime message.


threadMail

public Thread threadMail(javax.mail.internet.MimeMessage errmail,
                         boolean debug)
Sends a previously prepared mail or debugs. Fascinating enough this does not need a mail session anymore, everything is already packed into the mime message.


close

public void close()
           throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

createStellaRoboticMailer

public static final Mailer createStellaRoboticMailer()
Factory method to create a mailer for the robotic account on Google