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-netSMTPClientorSMTPSClientfor 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.SMTPClientm_Clientthe SMTP client.protected BasePasswordm_Passwordthe password to use for authentication.protected intm_Portthe server port.protected Stringm_Protocolsthe protocols to use.protected booleanm_RequiresAuthwhether authentication is required.protected Stringm_Serverthe server to connect to.protected intm_Timeoutthe timeout for the server.protected Stringm_Userthe user to use for authenticating.protected booleanm_UseSSLwhether to use SSL.protected booleanm_UseTLSwhether 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 StringglobalInfo()Returns a string describing the object.voidinitializeSmtpSession(String server, int port, boolean useTLS, boolean useSSL, int timeout, boolean requiresAuth, String user, BasePassword pw, String protocols)Initializes the SMTP session.booleanrequiresSmtpSessionInitialization()Returns whether the SMTP session needs to be initialized.booleansendMail(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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin 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:
requiresSmtpSessionInitializationin 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:
initializeSmtpSessionin 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:
sendMailin classAbstractSendEmail- Parameters:
email- the email to send- Returns:
- true if successfully sent
- Throws:
Exception- in case of invalid internet addresses or messaging problem
-
-