通过Python发送Outlook电子邮件?

通过Python发送Outlook电子邮件?,第1张

通过Python发送Outlook电子邮件

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

否则,请使用python随附的smtplib。请注意,这将要求您的电子邮件帐户允许smtp,默认情况下不一定启用此功能。

SERVER = "smtp.example.com"FROM = "[email protected]"TO = ["listOfEmails"] # must be a listSUBJECT = "Subject"TEXT = "Your Text"# Prepare actual messagemessage = """From: %srnTo: %srnSubject: %srn%s""" % (FROM, ", ".join(TO), SUBJECT, TEXT)# Send the mailimport smtplibserver = smtplib.SMTP(SERVER)server.sendmail(FROM, TO, message)server.quit()

编辑:示例使用保留域,如RFC2606中所述

SERVER = "smtp.example.com"FROM = "[email protected]"TO = ["[email protected]"] # must be a listSUBJECT = "Hello!"TEXT = "This is a test of emailing through smtp of example.com."# Prepare actual messagemessage = """From: %srnTo: %srnSubject: %srn%s""" % (FROM, ", ".join(TO), SUBJECT, TEXT)# Send the mailimport smtplibserver = smtplib.SMTP(SERVER)server.login("MrDoe", "PASSWORD")server.sendmail(FROM, TO, message)server.quit()

为了使它真正与gmail配合使用,Doe先生需要进入gmail中的选项标签并将其设置为允许smtp连接。

请注意,添加了登录行以对远程服务器进行身份验证。原始版本不包括此内容,我个人对此有所疏忽。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5623620.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存