smtpdelphi-xe5indy10

How to avoid "message rejected with no message-id" when using Indy smtp


On rare occasions my emails bounce back with the message:

Remote host said: 550-RFC2822 says that all mail SHOULD have a Message-ID header. 550 Most messages without it are spam, so your mail has been rejected.

I've tried setting a message-id header using:

IdMessage1.Headers.Values['Message-ID'] := id;

In this case id is a string in the format xxxxx at mydomain. However either that's not how to set a message-id header, or it's getting stripped by my smtp server (hosted by my isp.) I've noticed that emails sent from Outlook do get a message-id and they aren't stripped. Does anyone have any suggestions on how to supply the message-id header so it doesn't get stripped? Are there other headers that I should include as well? I've also emailed my isp in case it's a setting on their end but Outlook must do it somehow.


Solution

  • To provide a custom header when sending or saving an email, you have to use the TIdMessage.ExtraHeaders property instead. The TIdMessage.Headers property is used when receiving or loading an email.

    TIdMessage has a MsgId property that you can use instead. However, when sending an email, the MsgId property value is ignored, so you have to resort to TIdMessage.ExtraHeaders to send a custom Message-ID header. The TIdMessage.MsgId value is NOT ignored with saving an email, though.


    EDIT:

    As a followup for this - TIdMessage has now been updated with logic changes in how it handles the "Message-ID" and "In-Reply-To" headers:

    https://www.indyproject.org/2016/09/12/logic-changes-in-tidmessage-regarding-message-id-and-in-reply-to-headers/

    In a nutshell, the TIdMessage.MsgId property now generates a "Message-ID" header when creating a new email (you do not need to use the TIdMessage.ExtraHeaders property anymore, though you still can if needed), and the "In-Reply-To" header is no longer auto-generated using the current "Message-ID" header when the TIdMessage.InReplyTo property is blank.