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?