Class SendMailCommand
- java.lang.Object
-
- org.apache.jmeter.protocol.smtp.sampler.protocol.SendMailCommand
-
public class SendMailCommand extends Object
This class performs all tasks necessary to send a message (build message, prepare connection, send message). Provides getter-/setter-methods for an SmtpSampler-object to configure transport and message settings. The send-mail-command itself is started by the SmtpSampler-object.
-
-
Constructor Summary
Constructors Constructor Description SendMailCommand()Standard-Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttachment(File attachment)Adds an attachment to current message - to be called by SmtpSampler-objectvoidaddHeader(String headerName, String headerValue)Adds a header-part to current HashMap of headers - to be called by SmtpSampler-objectvoidclearAttachments()Clear all attachments for current messagevoidclearHeaders()Deletes all current headers in HashMapvoidexecute()Processes prepareMessage() and execute()voidexecute(Message message)Sends message to mailserver, waiting for delivery if using synchronous mode.List<File>getAttachments()Returns all attachment for current message - standard getterStringgetConnectionTimeout()Returns connection timeout for the SMTP-connection - returns the default connection timeout if no value has been supplied.CollectionPropertygetHeaders()Returns headers for current message - standard getterStringgetPassword()Returns password to authenticate at the mailserver - standard getterList<InternetAddress>getReceiverBCC()Returns receivers of current message asInternetAddress("bcc") - standard getterList<InternetAddress>getReceiverCC()Returns receivers of current message asInternetAddress("cc") - standard getterStringgetSender()Returns sender-address for current message - standard getterStringgetServerResponse()StringgetSmtpPort()Returns port to be used for SMTP-connection (standard 25 or 465) - standard getterStringgetSmtpServer()Returns FQDN or IP of SMTP-server to be used to send message - standard getterStringgetSubject()Returns subject for current message - standard getterStringgetTimeout()Returns timeout for the SMTP-connection - returns the default timeout if no value has been supplied.StringgetUsername()Returns username to authenticate at the mailserver - standard getterbooleangetUseSSL()Returns if SSL is used to send message - standard getterbooleangetUseStartTLS()Returns if StartTLS is used to transmit message - standard getterbooleanisEnforceStartTLS()Returns if StartTLS is enforced to secure the connection, i.e. no fallback is used (plain SMTP) - standard getterbooleanisSynchronousMode()Returns if synchronous-mode is used for current message (i.e. time for delivery, ... is measured) - standard getterbooleanisTrustAllCerts()Returns if sampler should trust all certificates - standard getterbooleanisUseAuthentication()Returns if authentication is used to access the mailserver - standard getterMessageprepareMessage()Prepares message prior to be sent via execute()-method, i.e. sets properties such as protocol, authentication, etc.voidsetAttachments(List<File> attachments)Adds attachments to current messagevoidsetConnectionTimeOut(String connectionTimeOut)voidsetEmlMessage(String emlMessage)Sets eml-message to be sentvoidsetEnableDebug(boolean selected)voidsetEnforceStartTLS(boolean enforceStartTLS)Instructs object to enforce StartTLS and not to fallback to plain SMTP-connection - to be called by SmtpSampler-objectvoidsetHeaderFields(CollectionProperty headerFields)Sets headers for current messagevoidsetMailBody(String body)Set the mail body.voidsetPassword(String password)Sets password to authenticate at the mailserver - to be called by SmtpSampler-objectvoidsetPlainBody(boolean plainBody)Set whether to send a plain body (i.e. not multipart/mixed)voidsetReceiverBCC(List<InternetAddress> receiverBCC)Sets receivers of current message ("bcc") - to be called by SmtpSampler-objectvoidsetReceiverCC(List<InternetAddress> receiverCC)Sets receivers of current message ("cc") - to be called by SmtpSampler-objectvoidsetReceiverTo(List<InternetAddress> receiverTo)Sets receivers of current message ("to") - to be called by SmtpSampler-objectvoidsetReplyTo(List<InternetAddress> replyTo)voidsetSender(String sender)Sets the sender-address for the current message - to be called by SmtpSampler-objectvoidsetSmtpPort(String smtpPort)Sets port to be used for SMTP-connection (standard 25 or 465) - to be called by SmtpSampler-objectvoidsetSmtpServer(String smtpServer)Sets FQDN or IP of SMTP-server to be used to send message - to be called by SmtpSampler-objectvoidsetSubject(String subject)Sets subject for current message - called by SmtpSampler-objectvoidsetSynchronousMode(boolean synchronousMode)Sets the use of synchronous-mode (i.e. time for delivery, ... is measured) - to be called by SmtpSampler-objectvoidsetTimeOut(String timeOut)voidsetTrustAllCerts(boolean trustAllCerts)Determines if SMTP-sampler should trust all certificates, no matter what CA - to be called by SmtpSampler-objectvoidsetTrustStoreToUse(String trustStoreToUse)Sets the path to the local truststore to be used for SSL / StartTLS - to be called by SmtpSampler-objectvoidsetUseAuthentication(boolean useAuthentication)Sets if authentication should be used to access the mailserver - to be called by SmtpSampler-objectvoidsetUseEmlMessage(boolean sendEmlMessage)voidsetUseLocalTrustStore(boolean useLocalTrustStore)Assigns the object to use a local truststore for SSL / StartTLS - to be called by SmtpSampler-objectvoidsetUsername(String username)Sets username to authenticate at the mailserver - to be called by SmtpSampler-objectvoidsetUseSSL(boolean useSSL)Sets SSL to secure the delivery channel for the message - to be called by SmtpSampler-objectvoidsetUseStartTLS(boolean useStartTLS)Sets StartTLS to secure the delivery channel for the message - to be called by SmtpSampler-object
-
-
-
Method Detail
-
prepareMessage
public Message prepareMessage() throws MessagingException, IOExceptionPrepares message prior to be sent via execute()-method, i.e. sets properties such as protocol, authentication, etc.- Returns:
- Message-object to be sent to execute()-method
- Throws:
MessagingException- when problems constructing or sending the mail occurIOException- when the mail content can not be read or truststore problems are detected
-
execute
public void execute(Message message) throws MessagingException, IOException, InterruptedExceptionSends message to mailserver, waiting for delivery if using synchronous mode.- Parameters:
message- Message previously prepared by prepareMessage()- Throws:
MessagingException- when problems sending the mail ariseIOException- TODO can not see howInterruptedException- when interrupted while waiting for delivery in synchronous modus
-
execute
public void execute() throws MessagingException, IOException, InterruptedExceptionProcesses prepareMessage() and execute()- Throws:
InterruptedException- when interrupted while waiting for delivery in synchronous modusIOException- when the mail content can not be read or truststore problems are detectedMessagingException- when problems constructing or sending the mail occur
-
getSmtpServer
public String getSmtpServer()
Returns FQDN or IP of SMTP-server to be used to send message - standard getter- Returns:
- FQDN or IP of SMTP-server
-
setSmtpServer
public void setSmtpServer(String smtpServer)
Sets FQDN or IP of SMTP-server to be used to send message - to be called by SmtpSampler-object- Parameters:
smtpServer- FQDN or IP of SMTP-server
-
getSender
public String getSender()
Returns sender-address for current message - standard getter- Returns:
- sender-address
-
setSender
public void setSender(String sender)
Sets the sender-address for the current message - to be called by SmtpSampler-object- Parameters:
sender- Sender-address for current message
-
getSubject
public String getSubject()
Returns subject for current message - standard getter- Returns:
- Subject of current message
-
setSubject
public void setSubject(String subject)
Sets subject for current message - called by SmtpSampler-object- Parameters:
subject- Subject for message of current message - may be null
-
getUsername
public String getUsername()
Returns username to authenticate at the mailserver - standard getter- Returns:
- Username for mailserver
-
setUsername
public void setUsername(String username)
Sets username to authenticate at the mailserver - to be called by SmtpSampler-object- Parameters:
username- Username for mailserver
-
getPassword
public String getPassword()
Returns password to authenticate at the mailserver - standard getter- Returns:
- Password for mailserver
-
setPassword
public void setPassword(String password)
Sets password to authenticate at the mailserver - to be called by SmtpSampler-object- Parameters:
password- Password for mailserver
-
setReceiverTo
public void setReceiverTo(List<InternetAddress> receiverTo)
Sets receivers of current message ("to") - to be called by SmtpSampler-object- Parameters:
receiverTo- List of receivers
-
getReceiverCC
public List<InternetAddress> getReceiverCC()
Returns receivers of current message asInternetAddress("cc") - standard getter- Returns:
- List of receivers
-
setReceiverCC
public void setReceiverCC(List<InternetAddress> receiverCC)
Sets receivers of current message ("cc") - to be called by SmtpSampler-object- Parameters:
receiverCC- List of receivers
-
getReceiverBCC
public List<InternetAddress> getReceiverBCC()
Returns receivers of current message asInternetAddress("bcc") - standard getter- Returns:
- List of receivers
-
setReceiverBCC
public void setReceiverBCC(List<InternetAddress> receiverBCC)
Sets receivers of current message ("bcc") - to be called by SmtpSampler-object- Parameters:
receiverBCC- List of receivers
-
isUseAuthentication
public boolean isUseAuthentication()
Returns if authentication is used to access the mailserver - standard getter- Returns:
- True if authentication is used to access mailserver
-
setUseAuthentication
public void setUseAuthentication(boolean useAuthentication)
Sets if authentication should be used to access the mailserver - to be called by SmtpSampler-object- Parameters:
useAuthentication- Should authentication be used to access mailserver?
-
getUseSSL
public boolean getUseSSL()
Returns if SSL is used to send message - standard getter- Returns:
- True if SSL is used to transmit message
-
setUseSSL
public void setUseSSL(boolean useSSL)
Sets SSL to secure the delivery channel for the message - to be called by SmtpSampler-object- Parameters:
useSSL- Should StartTLS be used to secure SMTP-connection?
-
getUseStartTLS
public boolean getUseStartTLS()
Returns if StartTLS is used to transmit message - standard getter- Returns:
- True if StartTLS is used to transmit message
-
setUseStartTLS
public void setUseStartTLS(boolean useStartTLS)
Sets StartTLS to secure the delivery channel for the message - to be called by SmtpSampler-object- Parameters:
useStartTLS- Should StartTLS be used to secure SMTP-connection?
-
getSmtpPort
public String getSmtpPort()
Returns port to be used for SMTP-connection (standard 25 or 465) - standard getter- Returns:
- Port to be used for SMTP-connection
-
setSmtpPort
public void setSmtpPort(String smtpPort)
Sets port to be used for SMTP-connection (standard 25 or 465) - to be called by SmtpSampler-object- Parameters:
smtpPort- Port to be used for SMTP-connection
-
isTrustAllCerts
public boolean isTrustAllCerts()
Returns if sampler should trust all certificates - standard getter- Returns:
- True if all Certificates are trusted
-
setTrustAllCerts
public void setTrustAllCerts(boolean trustAllCerts)
Determines if SMTP-sampler should trust all certificates, no matter what CA - to be called by SmtpSampler-object- Parameters:
trustAllCerts- Should all certificates be trusted?
-
setEnforceStartTLS
public void setEnforceStartTLS(boolean enforceStartTLS)
Instructs object to enforce StartTLS and not to fallback to plain SMTP-connection - to be called by SmtpSampler-object- Parameters:
enforceStartTLS- Should StartTLS be enforced?
-
isEnforceStartTLS
public boolean isEnforceStartTLS()
Returns if StartTLS is enforced to secure the connection, i.e. no fallback is used (plain SMTP) - standard getter- Returns:
- True if StartTLS is enforced
-
getHeaders
public CollectionProperty getHeaders()
Returns headers for current message - standard getter- Returns:
- CollectionProperty of headers for current message
-
setHeaderFields
public void setHeaderFields(CollectionProperty headerFields)
Sets headers for current message- Parameters:
headerFields- CollectionProperty of headers for current message
-
addHeader
public void addHeader(String headerName, String headerValue)
Adds a header-part to current HashMap of headers - to be called by SmtpSampler-object- Parameters:
headerName- Key for current headerheaderValue- Value for current header
-
clearHeaders
public void clearHeaders()
Deletes all current headers in HashMap
-
getAttachments
public List<File> getAttachments()
Returns all attachment for current message - standard getter- Returns:
- List of attachments for current message
-
setAttachments
public void setAttachments(List<File> attachments)
Adds attachments to current message- Parameters:
attachments- List of files to be added as attachments to current message
-
addAttachment
public void addAttachment(File attachment)
Adds an attachment to current message - to be called by SmtpSampler-object- Parameters:
attachment- File-object to be added as attachment to current message
-
clearAttachments
public void clearAttachments()
Clear all attachments for current message
-
isSynchronousMode
public boolean isSynchronousMode()
Returns if synchronous-mode is used for current message (i.e. time for delivery, ... is measured) - standard getter- Returns:
- True if synchronous-mode is used
-
setSynchronousMode
public void setSynchronousMode(boolean synchronousMode)
Sets the use of synchronous-mode (i.e. time for delivery, ... is measured) - to be called by SmtpSampler-object- Parameters:
synchronousMode- Should synchronous-mode be used?
-
setTimeOut
public void setTimeOut(String timeOut)
- Parameters:
timeOut- the timeOut to set
-
getTimeout
public String getTimeout()
Returns timeout for the SMTP-connection - returns the default timeout if no value has been supplied.- Returns:
- Timeout to be set for SMTP-connection
-
setConnectionTimeOut
public void setConnectionTimeOut(String connectionTimeOut)
- Parameters:
connectionTimeOut- the connectionTimeOut to set
-
getConnectionTimeout
public String getConnectionTimeout()
Returns connection timeout for the SMTP-connection - returns the default connection timeout if no value has been supplied.- Returns:
- Connection timeout to be set for SMTP-connection
-
setUseLocalTrustStore
public void setUseLocalTrustStore(boolean useLocalTrustStore)
Assigns the object to use a local truststore for SSL / StartTLS - to be called by SmtpSampler-object- Parameters:
useLocalTrustStore- Should a local truststore be used?
-
setTrustStoreToUse
public void setTrustStoreToUse(String trustStoreToUse)
Sets the path to the local truststore to be used for SSL / StartTLS - to be called by SmtpSampler-object- Parameters:
trustStoreToUse- Path to local truststore
-
setUseEmlMessage
public void setUseEmlMessage(boolean sendEmlMessage)
-
setEmlMessage
public void setEmlMessage(String emlMessage)
Sets eml-message to be sent- Parameters:
emlMessage- path to eml-message
-
setMailBody
public void setMailBody(String body)
Set the mail body.- Parameters:
body- the body of the mail
-
setPlainBody
public void setPlainBody(boolean plainBody)
Set whether to send a plain body (i.e. not multipart/mixed)- Parameters:
plainBody-trueif sending a plain body (i.e. not multipart/mixed)
-
getServerResponse
public String getServerResponse()
-
setEnableDebug
public void setEnableDebug(boolean selected)
-
setReplyTo
public void setReplyTo(List<InternetAddress> replyTo)
-
-