adams.core.net
Class JavaMailSendEmail

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.core.net.AbstractSendEmail
              extended by adams.core.net.JavaMailSendEmail
All Implemented Interfaces:
Debuggable, Destroyable, OptionHandler, SizeOfHandler, Serializable

public class JavaMailSendEmail
extends AbstractSendEmail

Uses JavaMail for sending emails.

Version:
$Revision: 7123 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
EmailHelper#initializeSmtpSession(String, int, boolean, int, boolean, String, BasePassword), EmailHelper#sendMail(Session, String, String[], String[], String[], String, String, File[]), Serialized Form

Field Summary
static String KEY_SMTPAUTH
          the system-wide property for SMTP Auth.
static String KEY_SMTPHOST
          the system-wide property for the SMTP host.
static String KEY_SMTPPORT
          the system-wide property for the SMTP port.
static String KEY_SMTPTIMEOUT
          the system-wide property for SMTP timeout.
static String KEY_STARTTLS
          the system-wide property for StartTLS.
protected  javax.mail.Session m_Session
          the SMTP session object.
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Constructor Summary
JavaMailSendEmail()
           
 
Method Summary
 String globalInfo()
          Returns a string describing the object.
 void initializeSmtpSession(String server, int port, boolean useTLS, int timeout, boolean requiresAuth, String user, BasePassword pw)
          Initializes the SMTP session.
protected  javax.mail.internet.MimeMessage newMessage(EmailAddress fromAddress, EmailAddress[] toAddress, EmailAddress[] ccAddress, EmailAddress[] bccAddress, String subject)
          Creates a new email message.
 boolean requiresSmtpSessionInitialization()
          Returns whether the SMTP session needs to be initialized.
 boolean sendMail(Email email)
          Sends an email.
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debug, debugLevelTipText, defineOptions, destroy, finishInit, getDebugLevel, getOptionManager, initialize, isDebugOn, newOptionManager, reset, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_SMTPHOST

public static final String KEY_SMTPHOST
the system-wide property for the SMTP host.

See Also:
Constant Field Values

KEY_SMTPPORT

public static final String KEY_SMTPPORT
the system-wide property for the SMTP port.

See Also:
Constant Field Values

KEY_STARTTLS

public static final String KEY_STARTTLS
the system-wide property for StartTLS.

See Also:
Constant Field Values

KEY_SMTPAUTH

public static final String KEY_SMTPAUTH
the system-wide property for SMTP Auth.

See Also:
Constant Field Values

KEY_SMTPTIMEOUT

public static final String KEY_SMTPTIMEOUT
the system-wide property for SMTP timeout.

See Also:
Constant Field Values

m_Session

protected transient javax.mail.Session m_Session
the SMTP session object.

Constructor Detail

JavaMailSendEmail

public JavaMailSendEmail()
Method Detail

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class AbstractOptionHandler
Returns:
a description suitable for displaying in the gui

requiresSmtpSessionInitialization

public boolean requiresSmtpSessionInitialization()
Returns whether the SMTP session needs to be initialized.

Specified by:
requiresSmtpSessionInitialization in class AbstractSendEmail
Returns:
true if the SMTP session needs to be initialized

initializeSmtpSession

public void initializeSmtpSession(String server,
                                  int port,
                                  boolean useTLS,
                                  int timeout,
                                  boolean requiresAuth,
                                  String user,
                                  BasePassword pw)
                           throws Exception
Initializes the SMTP session.

Specified by:
initializeSmtpSession in class AbstractSendEmail
Parameters:
server - the SMTP server
port - the SMTP port
useTLS - whether to use TLS
timeout - the timeout
requiresAuth - whether authentication is required
user - the SMTP user
pw - the SMTP password
Throws:
Exception - if initialization fails

newMessage

protected javax.mail.internet.MimeMessage newMessage(EmailAddress fromAddress,
                                                     EmailAddress[] toAddress,
                                                     EmailAddress[] ccAddress,
                                                     EmailAddress[] bccAddress,
                                                     String subject)
                                              throws javax.mail.internet.AddressException,
                                                     javax.mail.MessagingException
Creates a new email message.

Parameters:
fromAddress - the sender
toAddress - the recipients, can be null
ccAddress - the CC recipients, can be null
bccAddress - the BCC recipients, can be null
subject - the subject
Returns:
the email message
Throws:
javax.mail.internet.AddressException - in case of invalid internet addresses
javax.mail.MessagingException - in case of a messaging problem

sendMail

public boolean sendMail(Email email)
                 throws Exception
Sends an email.

Specified by:
sendMail in class AbstractSendEmail
Parameters:
email - the email to send
Returns:
true if successfully sent
Throws:
Exception - in case of invalid internet addresses or messaging problem


Copyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.