login about faq

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

asked Jun 14 '12 at 08:45

chilkat's gravatar image

chilkat ♦♦

edited Jun 14 '12 at 08:45

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).


answered Jun 14 '12 at 08:52

chilkat's gravatar image

chilkat ♦♦

Thanks for the help!

We attempted to follow your instructions, but can't seem to get it to work.

In our .net(C#) code we have this:

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

However,if we send an email to Gmail, the resulting Message-ID header value looks like this:

Message-ID: <4fdc5e45.c9bd440a.69c9.ffffe9dfSMTPIN_ADDED@mx.google.com>

As you can see, it's not using the value we supplied and it seems Gmail is adding its own Message-ID instead.

Any ideas?

(Jun 16 '12 at 10:39) 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


answered Jun 18 '12 at 17:28

chilkat's gravatar image

chilkat ♦♦

You're a genius!

We were able to get it working perfectly.


(Jun 19 '12 at 16:30) Robert

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.


answered Jun 18 '12 at 15:46

chilkat's gravatar image

chilkat ♦♦

Based on what I have read online, Gmail is creating its own Message-ID (with @mx.google.com) because it is NOT receiving a valid Message-ID when we send an email using the Chilkat library.

If I look at headers from old emails that we sent to Gmail (before trying out Chilkat), I can see that our custom header is used. And, if I look at other emails I have received from places that would have used a custom header, I can see their custom header too.

(Jun 18 '12 at 15:58) Robert

Of course, just to be thorough, we'll test this using a different email program other than Gmail and see what comes through.

I will update you if we notice that we are having success when using another email provider.

However, my gut (which could totally be wrong!) instinct is that we're not sending in a message-id that Google deems valid and that's why we're not seeing it.

Any other ideas?

(Jun 18 '12 at 15:58) Robert

By the way.... MANY MANY Thanks for your help. I look forward to getting this working and then using your library forever. =)

(Jun 18 '12 at 15:59) Robert
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Jun 14 '12 at 08:45

Seen: 9,255 times

Last updated: Jun 19 '12 at 16:30

powered by OSQA