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 void
addAttachment(File attachment)
Adds an attachment to current message - to be called by SmtpSampler-objectvoid
addHeader(String headerName, String headerValue)
Adds a header-part to current HashMap of headers - to be called by SmtpSampler-objectvoid
clearAttachments()
Clear all attachments for current messagevoid
clearHeaders()
Deletes all current headers in HashMapvoid
execute()
Processes prepareMessage() and execute()void
execute(Message message)
Sends message to mailserver, waiting for delivery if using synchronous mode.List<File>
getAttachments()
Returns all attachment for current message - standard getterString
getConnectionTimeout()
Returns connection timeout for the SMTP-connection - returns the default connection timeout if no value has been supplied.CollectionProperty
getHeaders()
Returns headers for current message - standard getterString
getPassword()
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 getterString
getSender()
Returns sender-address for current message - standard getterString
getServerResponse()
String
getSmtpPort()
Returns port to be used for SMTP-connection (standard 25 or 465) - standard getterString
getSmtpServer()
Returns FQDN or IP of SMTP-server to be used to send message - standard getterString
getSubject()
Returns subject for current message - standard getterString
getTimeout()
Returns timeout for the SMTP-connection - returns the default timeout if no value has been supplied.String
getUsername()
Returns username to authenticate at the mailserver - standard getterboolean
getUseSSL()
Returns if SSL is used to send message - standard getterboolean
getUseStartTLS()
Returns if StartTLS is used to transmit message - standard getterboolean
isEnforceStartTLS()
Returns if StartTLS is enforced to secure the connection, i.e. no fallback is used (plain SMTP) - standard getterboolean
isSynchronousMode()
Returns if synchronous-mode is used for current message (i.e. time for delivery, ... is measured) - standard getterboolean
isTrustAllCerts()
Returns if sampler should trust all certificates - standard getterboolean
isUseAuthentication()
Returns if authentication is used to access the mailserver - standard getterMessage
prepareMessage()
Prepares message prior to be sent via execute()-method, i.e. sets properties such as protocol, authentication, etc.void
setAttachments(List<File> attachments)
Adds attachments to current messagevoid
setConnectionTimeOut(String connectionTimeOut)
void
setEmlMessage(String emlMessage)
Sets eml-message to be sentvoid
setEnableDebug(boolean selected)
void
setEnforceStartTLS(boolean enforceStartTLS)
Instructs object to enforce StartTLS and not to fallback to plain SMTP-connection - to be called by SmtpSampler-objectvoid
setHeaderFields(CollectionProperty headerFields)
Sets headers for current messagevoid
setMailBody(String body)
Set the mail body.void
setPassword(String password)
Sets password to authenticate at the mailserver - to be called by SmtpSampler-objectvoid
setPlainBody(boolean plainBody)
Set whether to send a plain body (i.e. not multipart/mixed)void
setReceiverBCC(List<InternetAddress> receiverBCC)
Sets receivers of current message ("bcc") - to be called by SmtpSampler-objectvoid
setReceiverCC(List<InternetAddress> receiverCC)
Sets receivers of current message ("cc") - to be called by SmtpSampler-objectvoid
setReceiverTo(List<InternetAddress> receiverTo)
Sets receivers of current message ("to") - to be called by SmtpSampler-objectvoid
setReplyTo(List<InternetAddress> replyTo)
void
setSender(String sender)
Sets the sender-address for the current message - to be called by SmtpSampler-objectvoid
setSmtpPort(String smtpPort)
Sets port to be used for SMTP-connection (standard 25 or 465) - to be called by SmtpSampler-objectvoid
setSmtpServer(String smtpServer)
Sets FQDN or IP of SMTP-server to be used to send message - to be called by SmtpSampler-objectvoid
setSubject(String subject)
Sets subject for current message - called by SmtpSampler-objectvoid
setSynchronousMode(boolean synchronousMode)
Sets the use of synchronous-mode (i.e. time for delivery, ... is measured) - to be called by SmtpSampler-objectvoid
setTimeOut(String timeOut)
void
setTrustAllCerts(boolean trustAllCerts)
Determines if SMTP-sampler should trust all certificates, no matter what CA - to be called by SmtpSampler-objectvoid
setTrustStoreToUse(String trustStoreToUse)
Sets the path to the local truststore to be used for SSL / StartTLS - to be called by SmtpSampler-objectvoid
setUseAuthentication(boolean useAuthentication)
Sets if authentication should be used to access the mailserver - to be called by SmtpSampler-objectvoid
setUseEmlMessage(boolean sendEmlMessage)
void
setUseLocalTrustStore(boolean useLocalTrustStore)
Assigns the object to use a local truststore for SSL / StartTLS - to be called by SmtpSampler-objectvoid
setUsername(String username)
Sets username to authenticate at the mailserver - to be called by SmtpSampler-objectvoid
setUseSSL(boolean useSSL)
Sets SSL to secure the delivery channel for the message - to be called by SmtpSampler-objectvoid
setUseStartTLS(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, IOException
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:
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, InterruptedException
Sends 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, InterruptedException
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 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
-true
if 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)
-
-