Outlook 2010 和 Python 电子邮件 smtplib - 适当字段中的信息 [英] Outlook 2010 and Python email smtplib - info in proper fields

查看:76
本文介绍了Outlook 2010 和 Python 电子邮件 smtplib - 适当字段中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 2.6.5 中尝试使用 smtplib 通过 Outlook 2010 发送邮件时,我至少遇到了成功发送邮件的情况,但是 s.sendmail(FROM, TO, message) 没有将信息放入 From:、To: 和 Subject: 行中.

When trying to send mail through Outlook 2010 with smtplib in Python 2.6.5, I at least encounter success sending the message, but s.sendmail(FROM, TO, message) is not putting the information in the From:, To:, and Subject: lines for me.

我需要知道如何在 Outlook 2010 中正确使用 smtplib 发送电子邮件,以便收到的电子邮件中填写了邮件中的发件人:、收件人:和主题:字段.

I need to know how to send email using smtplib in Outlook 2010 properly so that the email is received with the From:, To:, and Subject: fields on the message filled in.

这是我的代码.我用谷歌搜索找到这个框架:

Here is my code. I googled to find this framework:

import smtplib

SERVER = 'mail.company.com'
FROM = 'jdoe@company.com'
TO = ['receiver1@company.com']
SUBJECT = "Test Subject SMTP"
TEXT = "If this is in the body of the email, test is a success!"

message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)



try:
    s = smtplib.SMTP(SERVER)
    s.sendmail(FROM, TO, message) # this line is not correctly putting info in proper fields for Outlook 2010
    s.quit()
    print "Successfully sent email."

except:

    import sys, traceback

    tb = sys.exc_info()[2]
    print "An error occurred on line " + str(tb.tb_lineno)
    print "Error: unable to send email"

输出是邮件发送成功.确实如此.只是不太对.

Output is that the email is successfully sent. And it is. Just not quite right.

推荐答案

尝试 s.set_debuglevel(1) 来检查发生了什么.

Try s.set_debuglevel(1) to check what is going on.

代码看起来没问题.

您可能会被 SMTP 拒绝:

You may be rejected on SMTP:

smtplib.SMTPRecipientsRefused: {'example@amail.com': (550, b'5.7.1 Unable to relay')}

这篇关于Outlook 2010 和 Python 电子邮件 smtplib - 适当字段中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆