Is it possible to capture the "Message-ID" of an email message sent using SmtpClient?

Using the SmtpClient and MailMessage classes in .NET to send email through the local mail server ( hMailServer ), I did not find a way to get the value of the Message-ID header of the sent message.

Idea

I am trying to programmatically track invalid messages, so I need to find a way to identify responses from the target SMTP server that rejects a specific message.

Now I thought to just remember the value of the Message-ID SMTP header and analyze the incoming messages for this identifier.

I tried to check the Headers collection after sending the message, but I did not find the Message-ID .

My question

Is it possible to get the Message-ID header value that my SMTP server adds while sending an instance of MailMessage ?

Update 2012-05-27

As this example, I successfully tried to manually create a Message-ID myself, before sending.

All my examples still work, so it seems like this is the solution to my question.

+6
source share
3 answers

The standard solution to your problem is VERP. Read Bernstein's original article to find out why Message-Id et al. are not reliable. http://cr.yp.to/proto/verp.txt

+2
source

You can add your own message identifier before sending an email. I am using the following code:

 Guid id = Guid.NewGuid(); //Save the id in your database mensajeEmail.Headers.Add("Message-Id", String.Format("<{0}@{1}>",id.ToString(),"mail.example.com")); 

Note. To download messages, I use OpenPop.Net , I check the message.Headers.InReplyTo property, and the message identifier appears.

+3
source

I use the MailKit library for .Net and SMTP Client.

I tried another solution to get the identifier of the message sent with the SMTP client to track any response messages.

Before sending a message, add a hidden identifier property to the message headers,

Check this sample

Now continue and send your message, wait about 10 seconds, then you will use the IMAP client to get the Sent Items folder and for each message in your folder, iterate over the message headers and check if any of them are == messageIdentity , now you Successfully intercept the sent message and get any information about it, such as ID, etc.

0
source

Source: https://habr.com/ru/post/916797/


All Articles