Apache JMeter

org.apache.jmeter.protocol.smtp.sampler.protocol
Class SendMailCommand

java.lang.Object
  extended by 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
SendMailCommand()
          Standard-Constructor
 
Method Summary
 void addAttachment(File attachment)
          Adds an attachment to current message - to be called by SmtpSampler-object
 void addHeader(String headerName, String headerValue)
          Adds a header-part to current HashMap of headers - to be called by SmtpSampler-object
 void clearAttachments()
          Clear all attachments for current message
 void clearHeaders()
          Deletes all current headers in HashMap
 void execute()
          Processes prepareMessage() and execute()
 void execute(javax.mail.Message message)
          Sends message to mailserver, waiting for delivery if using synchronous mode.
 List<File> getAttachments()
          Returns all attachment for current message - standard getter
 CollectionProperty getHeaders()
          Returns headers for current message - standard getter
 String getPassword()
          Returns password to authenticate at the mailserver - standard getter
 List<javax.mail.internet.InternetAddress> getReceiverBCC()
          Returns receivers of current message ("bcc") - standard getter
 List<javax.mail.internet.InternetAddress> getReceiverCC()
          Returns receivers of current message ("cc") - standard getter
 String getSender()
          Returns sender-address for current message - standard getter
 String getServerResponse()
           
 String getSmtpPort()
          Returns port to be used for SMTP-connection (standard 25 or 465) - standard getter
 String getSmtpServer()
          Returns FQDN or IP of SMTP-server to be used to send message - standard getter
 String getSubject()
          Returns subject for current message - standard getter
 String getUsername()
          Returns username to authenticate at the mailserver - standard getter
 boolean getUseSSL()
          Returns if SSL is used to send message - standard getter
 boolean getUseStartTLS()
          Returns if StartTLS is used to transmit message - standard getter
 boolean isEnforceStartTLS()
          Returns if StartTLS is enforced to secure the connection, i.e. no fallback is used (plain SMTP) - standard getter
 boolean isSynchronousMode()
          Returns if synchronous-mode is used for current message (i.e. time for delivery, ... is measured) - standard getter
 boolean isTrustAllCerts()
          Returns if sampler should trust all certificates - standard getter
 boolean isUseAuthentication()
          Returns if authentication is used to access the mailserver - standard getter
 javax.mail.Message 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 message
 void setEmlMessage(String emlMessage)
          Sets eml-message to be sent
 void 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-object
 void setHeaderFields(CollectionProperty headerFields)
          Sets headers for current message
 void setMailBody(String body)
          Set the mail body.
 void setPassword(String password)
          Sets password to authenticate at the mailserver - to be called by SmtpSampler-object
 void setPlainBody(boolean plainBody)
          Set whether to send a plain body (i.e. not multipart/mixed)
 void setReceiverBCC(List<javax.mail.internet.InternetAddress> receiverBCC)
          Sets receivers of current message ("bcc") - to be called by SmtpSampler-object
 void setReceiverCC(List<javax.mail.internet.InternetAddress> receiverCC)
          Sets receivers of current message ("cc") - to be called by SmtpSampler-object
 void setReceiverTo(List<javax.mail.internet.InternetAddress> receiverTo)
          Sets receivers of current message ("to") - to be called by SmtpSampler-object
 void setReplyTo(List<javax.mail.internet.InternetAddress> replyTo)
           
 void setSender(String sender)
          Sets the sender-address for the current message - to be called by SmtpSampler-object
 void setSmtpPort(String smtpPort)
          Sets port to be used for SMTP-connection (standard 25 or 465) - to be called by SmtpSampler-object
 void setSmtpServer(String smtpServer)
          Sets FQDN or IP of SMTP-server to be used to send message - to be called by SmtpSampler-object
 void setSubject(String subject)
          Sets subject for current message - called by SmtpSampler-object
 void setSynchronousMode(boolean synchronousMode)
          Sets the use of synchronous-mode (i.e. time for delivery, ... is measured) - to be called by SmtpSampler-object
 void setTrustAllCerts(boolean trustAllCerts)
          Determines if SMTP-sampler should trust all certificates, no matter what CA - to be called by SmtpSampler-object
 void setTrustStoreToUse(String trustStoreToUse)
          Sets the path to the local truststore to be used for SSL / StartTLS - to be called by SmtpSampler-object
 void setUseAuthentication(boolean useAuthentication)
          Sets if authentication should be used to access the mailserver - to be called by SmtpSampler-object
 void setUseEmlMessage(boolean sendEmlMessage)
           
 void setUseLocalTrustStore(boolean useLocalTrustStore)
          Assigns the object to use a local truststore for SSL / StartTLS - to be called by SmtpSampler-object
 void setUsername(String username)
          Sets username to authenticate at the mailserver - to be called by SmtpSampler-object
 void setUseSSL(boolean useSSL)
          Sets SSL to secure the delivery channel for the message - to be called by SmtpSampler-object
 void setUseStartTLS(boolean useStartTLS)
          Sets StartTLS to secure the delivery channel for the message - to be called by SmtpSampler-object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SendMailCommand

public SendMailCommand()
Standard-Constructor

Method Detail

prepareMessage

public javax.mail.Message prepareMessage()
                                  throws javax.mail.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:
javax.mail.MessagingException
IOException

execute

public void execute(javax.mail.Message message)
             throws javax.mail.MessagingException,
                    IOException,
                    InterruptedException
Sends message to mailserver, waiting for delivery if using synchronous mode.

Parameters:
message - Message prior prepared by prepareMessage()
Throws:
javax.mail.MessagingException
IOException
InterruptedException

execute

public void execute()
             throws Exception
Processes prepareMessage() and execute()

Throws:
Exception

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<javax.mail.internet.InternetAddress> receiverTo)
Sets receivers of current message ("to") - to be called by SmtpSampler-object

Parameters:
receiverTo - List of receivers

getReceiverCC

public List<javax.mail.internet.InternetAddress> getReceiverCC()
Returns receivers of current message ("cc") - standard getter

Returns:
List of receivers

setReceiverCC

public void setReceiverCC(List<javax.mail.internet.InternetAddress> receiverCC)
Sets receivers of current message ("cc") - to be called by SmtpSampler-object

Parameters:
receiverCC - List of receivers

getReceiverBCC

public List<javax.mail.internet.InternetAddress> getReceiverBCC()
Returns receivers of current message ("bcc") - standard getter

Returns:
List of receivers

setReceiverBCC

public void setReceiverBCC(List<javax.mail.internet.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 header
headerValue - 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?

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 -

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<javax.mail.internet.InternetAddress> replyTo)

Apache JMeter

Copyright © 1998-2013 Apache Software Foundation. All Rights Reserved.