title: Is it possible to capture the "Message-ID" of an email message sent with SmtpClient?
body: <p>Using the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient" rel="nofollow noreferrer"><code>SmtpClient</code></a> and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage" rel="nofollow noreferrer"><code>MailMessage</code> classes</a> in .NET to send emails through a local mail server (<a href="https://www.hmailserver.com/" rel="nofollow noreferrer">hMailServer</a>), I currently found no way to get the <code>Message-ID</code> header value of a sent message.</p>
  <p><strong>The idea behind</strong></p>
  <p>I'm trying to programmatically track messages that are undeliverable, so I have to find a way to identify replies from the destination SMTP server that rejects a certain message.</p>
  <p>Now I thought of simply remembering the <code>Message-ID</code> SMTP header value and parse incoming mails for this ID.</p>
  <p>I've tried to inspect the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage.headers#System_Net_Mail_MailMessage_Headers" rel="nofollow noreferrer"><code>Headers</code> collection</a> after sending the message, but I did not find any <code>Message-ID</code>.</p>
  <p><strong>My question</strong></p>
  <p>Is it possible to get the <code>Message-ID</code> header value that my SMTP server adds during sending of a <code>MailMessage</code> instance?</p>
  <p><strong>Update 2012-05-27</strong></p>
  <p>As per <a href="https://social.msdn.microsoft.com/Forums/en-US/c915a9f2-d31e-42f1-a837-a3466b102242/how-to-create-a-valid-messageid-using-netmail-on-windows-xp-net-20" rel="nofollow noreferrer">this example</a> I've successfully tried to manually generate a <code>Message-ID</code> on my own, just before sending.</p>
  <p>All my examples work so far, so it <em>seems</em> that this is a solution to my question.</p>