Class SendMailCommand
java.lang.Object
org.apache.jmeter.protocol.smtp.sampler.protocol.SendMailCommand
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachment(File attachment) Adds an attachment to current message - to be called by SmtpSampler-objectvoidAdds a header-part to current HashMap of headers - to be called by SmtpSampler-objectvoidClear all attachments for current messagevoidDeletes all current headers in HashMapvoidexecute()Processes prepareMessage() and execute()voidexecute(javax.mail.Message message) Sends message to mailserver, waiting for delivery if using synchronous mode.Returns all attachment for current message - standard getterReturns connection timeout for the SMTP-connection - returns the default connection timeout if no value has been supplied.Returns headers for current message - standard getterReturns password to authenticate at the mailserver - standard getterList<javax.mail.internet.InternetAddress>Returns receivers of current message asInternetAddress("bcc") - standard getterList<javax.mail.internet.InternetAddress>Returns receivers of current message asInternetAddress("cc") - standard getterReturns sender-address for current message - standard getterReturns port to be used for SMTP-connection (standard 25 or 465) - standard getterReturns FQDN or IP of SMTP-server to be used to send message - standard getterReturns subject for current message - standard getterReturns timeout for the SMTP-connection - returns the default timeout if no value has been supplied.Returns username to authenticate at the mailserver - standard getterbooleanReturns if SSL is used to send message - standard getterbooleanReturns if StartTLS is used to transmit message - standard getterbooleanReturns if StartTLS is enforced to secure the connection, i.e.booleanReturns if synchronous-mode is used for current message (i.e.booleanReturns if sampler should trust all certificates - standard getterbooleanReturns if authentication is used to access the mailserver - standard getterjavax.mail.MessagePrepares message prior to be sent via execute()-method, i.e.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.voidsetReceiverBCC(List<javax.mail.internet.InternetAddress> receiverBCC) Sets receivers of current message ("bcc") - to be called by SmtpSampler-objectvoidsetReceiverCC(List<javax.mail.internet.InternetAddress> receiverCC) Sets receivers of current message ("cc") - to be called by SmtpSampler-objectvoidsetReceiverTo(List<javax.mail.internet.InternetAddress> receiverTo) Sets receivers of current message ("to") - to be called by SmtpSampler-objectvoidsetReplyTo(List<javax.mail.internet.InternetAddress> replyTo) voidSets 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.voidsetTimeOut(String timeOut) voidsetTlsProtocolsToUse(String tlsProtocols) Sets the list of protocols to be used on TLS handshakevoidsetTrustAllCerts(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
-
Constructor Details
-
SendMailCommand
public SendMailCommand()Standard-Constructor
-
-
Method Details
-
prepareMessage
Prepares 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:
javax.mail.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(javax.mail.Message message) throws javax.mail.MessagingException, InterruptedException Sends message to mailserver, waiting for delivery if using synchronous mode.- Parameters:
message- Message previously prepared by prepareMessage()- Throws:
javax.mail.MessagingException- when problems sending the mail ariseInterruptedException- when interrupted while waiting for delivery in synchronous mode
-
execute
Processes 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 detectedjavax.mail.MessagingException- when problems constructing or sending the mail occur
-
getSmtpServer
Returns FQDN or IP of SMTP-server to be used to send message - standard getter- Returns:
- FQDN or IP of SMTP-server
-
setSmtpServer
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
Returns sender-address for current message - standard getter- Returns:
- sender-address
-
setSender
Sets the sender-address for the current message - to be called by SmtpSampler-object- Parameters:
sender- Sender-address for current message
-
getSubject
Returns subject for current message - standard getter- Returns:
- Subject of current message
-
setSubject
Sets subject for current message - called by SmtpSampler-object- Parameters:
subject- Subject for message of current message - may be null
-
getUsername
Returns username to authenticate at the mailserver - standard getter- Returns:
- Username for mailserver
-
setUsername
Sets username to authenticate at the mailserver - to be called by SmtpSampler-object- Parameters:
username- Username for mailserver
-
getPassword
Returns password to authenticate at the mailserver - standard getter- Returns:
- Password for mailserver
-
setPassword
Sets password to authenticate at the mailserver - to be called by SmtpSampler-object- Parameters:
password- Password for mailserver
-
setReceiverTo
Sets receivers of current message ("to") - to be called by SmtpSampler-object- Parameters:
receiverTo- List of receivers
-
getReceiverCC
Returns receivers of current message asInternetAddress("cc") - standard getter- Returns:
- List of receivers
-
setReceiverCC
Sets receivers of current message ("cc") - to be called by SmtpSampler-object- Parameters:
receiverCC- List of receivers
-
getReceiverBCC
Returns receivers of current message asInternetAddress("bcc") - standard getter- Returns:
- List of receivers
-
setReceiverBCC
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
Returns port to be used for SMTP-connection (standard 25 or 465) - standard getter- Returns:
- Port to be used for SMTP-connection
-
setSmtpPort
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
Returns headers for current message - standard getter- Returns:
- CollectionProperty of headers for current message
-
setHeaderFields
Sets headers for current message- Parameters:
headerFields- CollectionProperty of headers for current message
-
addHeader
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
Returns all attachment for current message - standard getter- Returns:
- List of attachments for current message
-
setAttachments
Adds attachments to current message- Parameters:
attachments- List of files to be added as attachments to current message
-
addAttachment
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
- Parameters:
timeOut- the timeOut to set
-
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
- Parameters:
connectionTimeOut- the connectionTimeOut to set
-
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
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
Sets eml-message to be sent- Parameters:
emlMessage- path to eml-message
-
setMailBody
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)
-
setEnableDebug
public void setEnableDebug(boolean selected) -
setReplyTo
-
setTlsProtocolsToUse
Sets the list of protocols to be used on TLS handshake- Parameters:
tlsProtocols- Space separated list
-
getTlsProtocolsToUse
-