While I still believe, that you are better of chasing the message-id,
you can try the attached patch, which should give you the message as a
header on the result sample.

Try your luck and report back :)

Felix

Am 11.04.21 um 15:23 schrieb Oren Nudelman:
> I am using also python smtplib for sending emails (on another project) and 
> they added a patch for getting back the response code and message text.
> https://github.com/python/cpython/pull/12148/files
> parsing the text should be user side business, but I expected javamail to at 
> least return a response object I ca work with.
>
> Earlier on this thread @Shay Ginsburg suggested parsing the jmeter debug and 
> parse the log file (where indeed this text exists) but it's a way more work 
> to parse large log file instead of a returned object.
>
> -----Original Message-----
> From: Felix Schumacher [mailto:felix.schumac...@internetallee.de] 
> Sent: Sunday, 11 April 2021 11:47
> To: user@jmeter.apache.org
> Subject: Re: SMTP Handler - get queue id
>
>
> Am 11.04.21 um 10:17 schrieb Oren Nudelman:
>> Hi ,
>>
>> Thank you for the feedback.
>> I need the queue id so I can later track the mail on our logs (in case of 
>> delivery problems).
> In that case, I would go with the message-id header. Postfix will log it and 
> it is in the mail headers. Plus, it will be in the mails on the destination 
> server and can be seen in the clients.
>> I am not sure if all smtp server return it on the response. Testing it 
>> via telnet with postfix I get it
>>
>> 220 <ommitted> ESMTP Postfix (Ubuntu)
>> ehlo <ommitted>
>> 250-<ommitted>
>> 250-PIPELINING
>> 250-SIZE 10240000
>> 250-VRFY
>> 250-ETRN
>> 250-STARTTLS
>> 250-AUTH PLAIN LOGIN
>> 250-AUTH=PLAIN LOGIN
>> 250-ENHANCEDSTATUSCODES
>> 250-8BITMIME
>> 250 DSN
>> mail from:<ommitted>
>> 250 2.1.0 Ok
>> rcpt to:<ommitted>
>> 250 2.1.5 Ok
>> data
>> 354 End data with <CR><LF>.<CR><LF>
>> bla
>> .
>> 250 2.0.0 Ok: queued as AE804D63A22
> But according to RFC 5321 Section 4.2 the text part (which would be
> 2.0.0 Ok: queued as AE..) is optional (if I interpret it correctly). I didn't 
> find anything specifying a format for the Ok text message. It seems to be not 
> defined. Implementing a parser for that information seems to be a tricky 
> thing and I would not suggest doing it without more information.
>
> Felix
>
>> -----Original Message-----
>> From: Felix Schumacher [mailto:felix.schumac...@internetallee.de]
>> Sent: Thursday, 8 April 2021 13:44
>> To: user@jmeter.apache.org
>> Subject: Re: SMTP Handler - get queue id
>>
>>
>> Am 07.04.21 um 15:38 schrieb Oren Nudelman:
>>> Hi ,
>>>
>>> I am trying to get back the queue id in the SMTP response when sending 
>>> email using SMTP handler.
>>> I can see it in the logs when enabling debug but could not find any way to 
>>> retrieve it during execution.
>> With "can see it in the logs", you probably the logs from the Java mail api. 
>> I don't think that there is (currently) an easy way to parse those or to get 
>> at the queue id by other means from within JMeter.
>>
>> Why do you want to get the queue id?
>>
>> If you really need it, you could open an enhancement issue on the bug 
>> tracker. After dabbling a bit, I think we could parse the queue-id from the 
>> Transport instance in the sendmailcommand by issuing getLastServerResponse 
>> on it. But, it is unclear to me, whether the queue id is always part of the 
>> response and the call chain in JMeter doesn't allow the addition of that 
>> information in a trivial way (at least not at first glance).
>>
>> Felix
>>
>>> Anyone?
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org
>> For additional commands, e-mail: user-h...@jmeter.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org
> For additional commands, e-mail: user-h...@jmeter.apache.org
From b30d9557ab0faed0d30cbafb3d24614b6c0ab328 Mon Sep 17 00:00:00 2001
From: Felix Schumacher <felix.schumac...@internetallee.de>
Date: Sun, 11 Apr 2021 15:52:49 +0200
Subject: [PATCH] Make smtp answer to data available as header

---
 .../apache/jmeter/protocol/smtp/sampler/SmtpSampler.java    | 4 ++++
 .../protocol/smtp/sampler/protocol/SendMailCommand.java     | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
index f648b48d01..cb2d6b6819 100644
--- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
+++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
@@ -170,6 +170,10 @@ public class SmtpSampler extends AbstractSampler {
         boolean didSampleSucceed = false;
         try {
             sendMailCmd.execute(message);
+            final String[] response_headers = message.getHeader(SendMailCommand.SMTP_RESPONSE_MESSAGE);
+            if (response_headers.length > 0) {
+                result.setResponseHeaders(SendMailCommand.SMTP_RESPONSE_MESSAGE + ": " + response_headers[0]);
+            }
             result.setResponseCodeOK();
             result.setResponseMessage(
                     "Message successfully sent!\n");
diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
index 9153df2ac8..575ff301ae 100644
--- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
+++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
@@ -52,6 +52,8 @@ import org.apache.jmeter.util.TrustAllSSLSocketFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.sun.mail.smtp.SMTPTransport;
+
 /**
  * This class performs all tasks necessary to send a message (build message,
  * prepare connection, send message). Provides getter-/setter-methods for an
@@ -60,6 +62,7 @@ import org.slf4j.LoggerFactory;
  */
 public class SendMailCommand {
 
+    public static final String SMTP_RESPONSE_MESSAGE = "X-JMeter-SMTP-Response-Message";
     // local vars
     private static final Logger logger = LoggerFactory.getLogger(SendMailCommand.class);
     private static final String MAIL_PROPERTY_PREFIX = "mail.";
@@ -326,6 +329,9 @@ public class SendMailCommand {
             }
 
             tr.sendMessage(message, message.getAllRecipients());
+            if (tr instanceof SMTPTransport) {
+                message.addHeader(SMTP_RESPONSE_MESSAGE, ((SMTPTransport) tr).getLastServerResponse());
+            }
 
             if (listener != null /*synchronousMode==true*/) {
                 listener.attend(); // listener cannot be null here
-- 
2.25.1

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to