Package adams.core.net
Class JavaMailSendEmail
-
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,Serializable
public class JavaMailSendEmail extends AbstractSendEmail
Uses JavaMail for sending emails.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
KEY_PROTOCOLS
the protocols property.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_SMTPSAUTH
the system-wide property for SMTPS Auth.static String
KEY_SMTPSHOST
the system-wide property for the SMTPS host.static String
KEY_SMTPSPORT
the system-wide property for the SMTPS port.static String
KEY_SMTPSTIMEOUT
the system-wide property for SMTPS timeout.static String
KEY_SMTPTIMEOUT
the system-wide property for SMTP timeout.static String
KEY_STARTTLS
the system-wide property for StartTLS.static String
KEY_USESSL
the system-wide property for using SSL.protected javax.mail.Session
m_Session
the SMTP session object.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description JavaMailSendEmail()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
globalInfo()
Returns a string describing the object.void
initializeSmtpSession(String server, int port, boolean useTLS, boolean useSSL, int timeout, boolean requiresAuth, String user, BasePassword pw, String protocols)
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.net.AbstractSendEmail
cleanUp
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, defineOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
KEY_SMTPHOST
public static final String KEY_SMTPHOST
the system-wide property for the SMTP host.- See Also:
- Constant Field Values
-
KEY_SMTPSHOST
public static final String KEY_SMTPSHOST
the system-wide property for the SMTPS 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_SMTPSPORT
public static final String KEY_SMTPSPORT
the system-wide property for the SMTPS 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_USESSL
public static final String KEY_USESSL
the system-wide property for using SSL.- 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_SMTPSAUTH
public static final String KEY_SMTPSAUTH
the system-wide property for SMTPS 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
-
KEY_SMTPSTIMEOUT
public static final String KEY_SMTPSTIMEOUT
the system-wide property for SMTPS timeout.- See Also:
- Constant Field Values
-
KEY_PROTOCOLS
public static final String KEY_PROTOCOLS
the protocols property.- See Also:
- Constant Field Values
-
m_Session
protected transient javax.mail.Session m_Session
the SMTP session object.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- 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 classAbstractSendEmail
- Returns:
- true if the SMTP session needs to be initialized
-
initializeSmtpSession
public void initializeSmtpSession(String server, int port, boolean useTLS, boolean useSSL, int timeout, boolean requiresAuth, String user, BasePassword pw, String protocols) throws Exception
Initializes the SMTP session.- Specified by:
initializeSmtpSession
in classAbstractSendEmail
- Parameters:
server
- the SMTP serverport
- the SMTP portuseTLS
- whether to use TLSuseSSL
- whether to use SSLtimeout
- the timeoutrequiresAuth
- whether authentication is requireduser
- the SMTP userpw
- the SMTP passwordprotocols
- the protocols to use, empty for default- 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 sendertoAddress
- the recipients, can be nullccAddress
- the CC recipients, can be nullbccAddress
- the BCC recipients, can be nullsubject
- the subject- Returns:
- the email message
- Throws:
javax.mail.internet.AddressException
- in case of invalid internet addressesjavax.mail.MessagingException
- in case of a messaging problem
-
sendMail
public boolean sendMail(Email email) throws Exception
Sends an email.- Specified by:
sendMail
in classAbstractSendEmail
- Parameters:
email
- the email to send- Returns:
- true if successfully sent
- Throws:
Exception
- in case of invalid internet addresses or messaging problem
-
-