0 votes
by (480 points)

I create an email without message id and send the mail, I then store it after it is sent. I find that the message id of the stored mail and the message id of the same email from the recipient account do not match.

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (144k points)

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.

by (480 points)
I am doing it this way. In the above code if I connect to outlook.com smtp server and logged using login.

var mail = new MailMessage();
mail.From = "bob@example.org";
mail.To = "support@rebex.net";
mail.Subject = "Sample subject";
mail.BodyText = "Sample text.";

mail.MessageId = null;

// send the mail message
var client = new Smtp();
client.LogWriter = new ConsoleLogWriter(LogLevel.Debug);
client.Connect(serverName, SslMode.Explicit);
client.Login("uname","password");
client.Send(mail);
client.Disconnect();

In this scenario outlook.com adds its message id.

If I try from yahoo or AOL emails, they do not store a copy in sent folder.

So for all the above cases,  is there a possibility of returning the message id that the server added on the recipient email.
by (144k points)
Yes, when you explicitly set MessageId to null, the Smtp object will send the message without it, and your SMTP server might add a unique Message-ID header on its own. We are not aware of any way to retrieve this information from the SMTP server.
However, why don't you simply keep the MessageId generated by MailMessage? This will prevent the server of adding its own header, and it's also what all mail apps do.
...