What's the easiest/cleanest way to get the MessageID of a sent email?
I want to save the MessageID of a sent email, so I can later use it in a References: header to facilitate threading.
I see in root/django/trunk/django/core/mail.py (line ~55) where the MessageID is created.
I'm trying to think of the best way to collect this value, other than just copy/pasting into a new backend module and returning it. Maybe that i开发者_运维百科s the best way?
Ok, I see I was browsing tragically old code. I should be able to call django.core.mail.message.make_msgid() and populate the header myself before calling send.
Not all backends actually support asserting a message id (for e.g. SES sets it's own message ID and returns it in it's send response). You can actually pull out the returned/generated/set message id if you use the newer (circa 1.1?) EmailMessage class you can extract the returned message ID from the instance once you call .send(), e.g.:
e=EmailMessage(
subject,
content,
from_email,
recipient_list,
headers = headers,
)
e.send()
message_id = e.extra_headers.get('Message-Id',None)
精彩评论