Tohid
Tohid

Reputation: 22573

Why emails sent by .NET SmtpClient are missing Message-Id?

This is my SMTP settings in App.Config:

<system.net>
    <mailSettings>
      <smtp from="Reminder &lt;[email protected]&gt;">
        <network host="mail.myserver.net" port="587" password="my password" userName="[email protected]" enableSsl="true"/>
      </smtp>
    </mailSettings>
  </system.net>

And this is how I'm sending the emails:

message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
smtpClient.Send(message);

this is working ! but the only problem is, my emails are going to spam folder and that's because they are missing Message-Id in their header. I use the same account in Thunderbird, when I send emails using thunderbird the Message-Id is added to my emails but it's not happening for the emails that are sent from my application.

I can add the header manually with something like :

message.Headers.Add("Message-Id","<3BD50098E401463AA228377848493927-1>");

But this Id is not a valid message-id and I will still get negative spam score for it. Any idea why this is happening ?

This is what I have in Thunderbird:
host: mail.korax.net /
authentication: normal password /
port: 587 /
security: STARTTLS

Upvotes: 17

Views: 17306

Answers (2)

John
John

Reputation: 2802

Please also see this article here:

http://jarrett.co/post/1638578964/spamassassin-vs-system-net-mail

I was getting the same issue. System.Net.Mail will not append a Message-Id automatically. But you can like so:

mailMessage.Headers.Add("Message-Id",
                         String.Format("<{0}@{1}>",
                         Guid.NewGuid().ToString(),
                        "mail.example.com"));

Upvotes: 25

Mark Cidade
Mark Cidade

Reputation: 100027

Your SMTP server has to be configured to automatically include the message ID. If generating your own ID, it should follow RFC 2822 Section 3.6.4.

Upvotes: 12

Related Questions