When you create an email without message ID, the MailMessage
object will generate a message ID for you.
However, I was unable to reproduce the issue you describe. I tried it with Gmail and Microsoft Exchange, and with both of these servers, the message ID of the received message corresponds to the ID of the locally sent message.
This is the code I used:
// create a mail message
var mail = new MailMessage();
mail.From = "bob@example.org";
mail.To = "support@rebex.net";
mail.Subject = "Sample subject";
mail.BodyText = "Sample text.";
// send the mail message
var client = new Smtp();
client.LogWriter = new ConsoleLogWriter(LogLevel.Debug);
client.Connect(serverName, SslMode.Explicit);
client.Login(SmtpAuthentication.Auto);
client.Send(mail);
client.Disconnect();
// save the mail message
mail.Save("sample.eml");
In my tests, the Message-ID
header in the sample.eml
file was the same as Message-ID
of the message in recipient's mailbox.
If you get different results, please let us know what you are doing differently.