I'm sending lots of similar emails out via SMTP using the following Python snippet:
def send(from_, to, body):
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login('[email protected]', password)
msg = '''\
From: %s
To: %s
Subject: %s
%s''' % (from_, to.encode('utf-8'), "Hello", body.encode('utf-8'))
server.sendmail(from_, to, msg)
server.quit()
These messages are the first messages in a conversation. Strangley, replies to these messages are not being threaded onto the original message's conversation.
A reply comes back as a separate message in my inbox, subject = "Re: Hello", with no tie to the original. (Very occasionally one will be threaded properly, which is even weirder.)
I've verified that these (un-threaded) replies have a References: field that refers to the sent mail's Message-ID field, which was autogenerated by GMail.
Any idea what I'm doing wrong?
For non-Gmail clients, Gmail supports the standard IMAP, POP, and SMTP protocols. The Gmail IMAP, POP, and SMTP servers have been extended to support authorization via the industry-standard OAuth 2.0 protocol.
Look at the References:
header. It contains a chain of the previous Message-ID:
headers in the thread, and is typically used for threading. It's usually a good idea to specify the Message-ID:
yourself, and if you keep track of your previously used ones, you can use them in the References:
header to enforce threading.
The Message-ID
should be globally unique. They're often constructed as something like this, but it's not a requirement.
Message-ID: unixtimestamp.somerandomval@sending-hostname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With