use of org.apache.jmeter.protocol.smtp.sampler.protocol.SendMailCommand in project jmeter by apache.
the class SmtpSampler method sample.
/**
* Performs the sample, and returns the result
*
* @param e Standard-method-header from JMeter
* @return Result of the sample
* @see org.apache.jmeter.samplers.Sampler#sample(org.apache.jmeter.samplers.Entry)
*/
@Override
public SampleResult sample(Entry e) {
SendMailCommand sendMailCmd;
Message message;
SampleResult result = createSampleResult();
try {
sendMailCmd = createSendMailCommandFromProperties();
message = sendMailCmd.prepareMessage();
result.setBytes(calculateMessageSize(message));
} catch (Exception ex) {
log.warn("Error while preparing message", ex);
result.setResponseCode("500");
result.setResponseMessage(ex.toString());
return result;
}
// Set up the sample result details
result.setDataType(SampleResult.TEXT);
try {
result.setRequestHeaders(getRequestHeaders(message));
result.setSamplerData(getSamplerData(message));
} catch (MessagingException | IOException ex) {
result.setSamplerData("Error occurred trying to save request info: " + ex);
log.warn("Error occurred trying to save request info", ex);
}
// Perform the sampling
result.sampleStart();
boolean isSuccessful = executeMessage(result, sendMailCmd, message);
result.sampleEnd();
try {
result.setResponseData(processSampler(message));
} catch (IOException | MessagingException ex) {
log.warn("Failed to set result response data", ex);
}
result.setSuccessful(isSuccessful);
return result;
}
use of org.apache.jmeter.protocol.smtp.sampler.protocol.SendMailCommand in project jmeter by apache.
the class SmtpSampler method createSendMailCommandFromProperties.
private SendMailCommand createSendMailCommandFromProperties() throws AddressException {
SendMailCommand sendMailCmd = new SendMailCommand();
sendMailCmd.setSmtpServer(getPropertyAsString(SmtpSampler.SERVER));
sendMailCmd.setSmtpPort(getPropertyAsString(SmtpSampler.SERVER_PORT));
sendMailCmd.setConnectionTimeOut(getPropertyAsString(SmtpSampler.SERVER_CONNECTION_TIMEOUT));
sendMailCmd.setTimeOut(getPropertyAsString(SmtpSampler.SERVER_TIMEOUT));
sendMailCmd.setUseSSL(getPropertyAsBoolean(SecuritySettingsPanel.USE_SSL));
sendMailCmd.setUseStartTLS(getPropertyAsBoolean(SecuritySettingsPanel.USE_STARTTLS));
sendMailCmd.setTrustAllCerts(getPropertyAsBoolean(SecuritySettingsPanel.SSL_TRUST_ALL_CERTS));
sendMailCmd.setEnforceStartTLS(getPropertyAsBoolean(SecuritySettingsPanel.ENFORCE_STARTTLS));
sendMailCmd.setUseAuthentication(getPropertyAsBoolean(USE_AUTH));
sendMailCmd.setUsername(getPropertyAsString(USERNAME));
sendMailCmd.setPassword(getPropertyAsString(PASSWORD));
sendMailCmd.setUseLocalTrustStore(getPropertyAsBoolean(SecuritySettingsPanel.USE_LOCAL_TRUSTSTORE));
sendMailCmd.setTrustStoreToUse(getPropertyAsString(SecuritySettingsPanel.TRUSTSTORE_TO_USE));
sendMailCmd.setEmlMessage(getPropertyAsString(EML_MESSAGE_TO_SEND));
sendMailCmd.setUseEmlMessage(getPropertyAsBoolean(USE_EML));
if (!getPropertyAsBoolean(USE_EML)) {
// if we are not sending an .eml file
sendMailCmd.setMailBody(getPropertyAsString(MESSAGE));
sendMailCmd.setPlainBody(getPropertyAsBoolean(PLAIN_BODY));
getAttachmentFiles().forEach(sendMailCmd::addAttachment);
}
sendMailCmd.setEnableDebug(getPropertyAsBoolean(ENABLE_DEBUG));
if (getPropertyAsString(MAIL_FROM).matches(".*@.*")) {
sendMailCmd.setSender(getPropertyAsString(MAIL_FROM));
}
// Process address lists
sendMailCmd.setReceiverTo(getPropAsAddresses(SmtpSampler.RECEIVER_TO));
sendMailCmd.setReceiverCC(getPropAsAddresses(SmtpSampler.RECEIVER_CC));
sendMailCmd.setReceiverBCC(getPropAsAddresses(SmtpSampler.RECEIVER_BCC));
sendMailCmd.setReplyTo(getPropAsAddresses(SmtpSampler.MAIL_REPLYTO));
sendMailCmd.setSubject(calculateSubject());
// needed for measuring sending time
sendMailCmd.setSynchronousMode(true);
sendMailCmd.setHeaderFields((CollectionProperty) getProperty(SmtpSampler.HEADER_FIELDS));
return sendMailCmd;
}
Aggregations