开发者

Why are replies to my SMTP-sent gmail messages not threaded?

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('michael@gmail.com', 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 f开发者_Python百科ield, which was autogenerated by GMail.

Any idea what I'm doing wrong?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜