Package adams.core.net
Class ApacheSendEmail
-
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,Serializable
public class ApacheSendEmail extends AbstractSendEmail
Uses Apache commons-netSMTPClient
orSMTPSClient
for sending emails.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.net.smtp.SMTPClient
m_Client
the SMTP client.protected BasePassword
m_Password
the password to use for authentication.protected int
m_Port
the server port.protected String
m_Protocols
the protocols to use.protected boolean
m_RequiresAuth
whether authentication is required.protected String
m_Server
the server to connect to.protected int
m_Timeout
the timeout for the server.protected String
m_User
the user to use for authenticating.protected boolean
m_UseSSL
whether to use SSL.protected boolean
m_UseTLS
whether to use TLS.-
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 ApacheSendEmail()
-
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.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
-
m_Client
protected transient org.apache.commons.net.smtp.SMTPClient m_Client
the SMTP client.
-
m_Server
protected String m_Server
the server to connect to.
-
m_Port
protected int m_Port
the server port.
-
m_UseTLS
protected boolean m_UseTLS
whether to use TLS.
-
m_Protocols
protected String m_Protocols
the protocols to use.
-
m_UseSSL
protected boolean m_UseSSL
whether to use SSL.
-
m_Timeout
protected int m_Timeout
the timeout for the server.
-
m_RequiresAuth
protected boolean m_RequiresAuth
whether authentication is required.
-
m_User
protected String m_User
the user to use for authenticating.
-
m_Password
protected BasePassword m_Password
the password to use for authentication.
-
-
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
-
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
-
-