+1 vote

How to send the message id after sending the mail.

IMail email = builder.Create();

smtp.SendMessage(email);

smtp.Close();

I am sending using above code after mail send is done i need a Message ID.

Please suggest how do i get it.

by

1 Answer

0 votes

Message ID is assigned by the client before it sends an email.

You can either rely on Mail.dll generating one or assign one yourself:

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("from@example.com"));
builder.To.Add(new MailBox("to@example.com"));
builder.Html = "Body";
builder.Subject = "Subject";

//You can set Message ID here:
//builder.MessageID = Guid.NewGuid() + "@example.com";

IMail mail = builder.Create();
string messageId = mail.MessageID;

using (Smtp smtp = new Smtp())
{
    smtp.Connect("smtp.server.com");  
    smtp.UseBestLogin("user", "password");

    smtp.SendMessage(mail);

    smtp.Close();
}
by (301k points)
...