我在项目中添加了Outlook邮件解析功能。现在,我想使用python代码回复特定的电子邮件。
该怎么做?
答案 0 :(得分:0)
这是我的看法。我认为应该明确设置“ Reply-To”标头。可能的原因是,它比“ Subject”,“ To”和“ From”之类的标题使用得更少。
python
Python 2.6.6 (r266:84292, May 10 2011, 11:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> MAIL_SERVER = 'smtp.domain.com'
>>> TO_ADDRESS = 'you@gmail.com'
>>> FROM_ADDRESS = 'email@domain.com'
>>> REPLY_TO_ADDRESS = 'email2@domain2.com'
>>> import smtplib
>>> import email.mime.multipart
>>> msg = email.mime.multipart.MIMEMultipart()
>>> msg['to'] = TO_ADDRESS
>>> msg['from'] = FROM_ADDRESS
>>> msg['subject'] = 'testing reply-to header'
>>> msg.add_header('reply-to', REPLY_TO_ADDRESS)
>>> server = smtplib.SMTP(MAIL_SERVER)
>>> server.sendmail(msg['from'], [msg['to']], msg.as_string())
{}