Archived Forum Post

Index of archived forum posts

Question:

Sending Email with a Custom Message-ID Header

Jun 19 '12 at 16:30

(Question from Chilkat customer via email)
How can I explicitly set the Message-ID header when sending email?


Answer

The Message-ID header is somewhat special because it should be unique for each email sent. It is also one of the default header fields that is added whenever a new Chilkat email object is instantiated.

The answer to this question involves the mailman.AutoGenMessageId property, which has a default value of True. The online reference documentation provides more information, but I'll reproduce it here:

"Controls whether a unique Message-ID header is auto-generated for each email sent.

The Message-ID header field should contain a unique message ID for each email that is sent. The default behavior is to auto-generate this header field at the time the message is sent. This makes it easier for the same email object to be re-used. If the message ID is not unique, the SMTP server may consider the message to be a duplicate of one that has already been sent, and may discard it without sending. This property controls whether message IDs are automatically generated. If auto-generation is turned on (true), the value returned by GetHeaderField("Message-ID") will not reflect the actual message ID that gets sent with the email.

To turn off automatic Message-ID generation, set this property to false."

Once AutoGenMessageId is turned off, the Message-ID header may be added/changed just like any other header field (via the email.AddHeaderField method, which adds or replaces a header field).


Answer

Robert,

You're very welcome. I think your custom Message-ID might be invalid because it's missing the "<" and ">" delimiters at each end. For example, try changing your code to this:

email.AddHeaderField("Message-ID", "<3654365244fdc532e.24aqee44ew0a.6d84.53476qa3545364531543509798.msgtest1.kumar@sample.com>");

See this web page about Message-ID format.

Best Regards, Matt


Answer

I think GMail is doing it. Chilkat wouldn't be generating a Message-ID that has "mx.google.com" in it, so the only explanation is that smtp.gmail.com is modifying the header.