通过 Python 发送 Outlook 电子邮件? [英] Send Outlook Email Via Python?

查看:60
本文介绍了通过 Python 发送 Outlook 电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Outlook 2003.

使用 Python 发送电子邮件的最佳方式是什么(通过 Outlook 2003)?

What is the best way to send email (through Outlook 2003) using Python?

推荐答案

有关使用 Outlook 的解决方案,请参阅下面的 TheoretiCAL 答案.

For a solution that uses outlook see TheoretiCAL's answer below.

否则使用python自带的smtplib.请注意,这将要求您的电子邮件帐户允许 smtp,默认情况下不一定启用.

Otherwise, use the smtplib that comes with python. Note that this will require your email account allows smtp, which is not necessarily enabled by default.

SERVER = "smtp.example.com"
FROM = "yourEmail@example.com"
TO = ["listOfEmails"] # must be a list

SUBJECT = "Subject"
TEXT = "Your Text"

# Prepare actual message
message = """From: %s
To: %s
Subject: %s


%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail
import smtplib
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()

此示例使用了RFC2606<中描述的保留域/a>

this example uses reserved domains like described in RFC2606

SERVER = "smtp.example.com"
FROM = "johnDoe@example.com"
TO = ["JaneDoe@example.com"] # must be a list

SUBJECT = "Hello!"
TEXT = "This is a test of emailing through smtp of example.com."

# Prepare actual message
message = """From: %s
To: %s
Subject: %s


%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail
import smtplib
server = smtplib.SMTP(SERVER)
server.login("MrDoe", "PASSWORD")
server.sendmail(FROM, TO, message)
server.quit()

要真正使用 gmail,Doe 先生需要转到 gmail 中的选项选项卡并将其设置为允许 smtp 连接.

请注意添加了登录行以对远程服务器进行身份验证.原始版本不包含此内容,这是我的疏忽.

Note the addition of the login line to authenticate to the remote server. The original version does not include this, an oversight on my part.

这篇关于通过 Python 发送 Outlook 电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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