简体   繁体   English

Python:如何将电子邮件文本正文传递给Office365电子邮件

[英]Python: How to pass email text body to Office365 Email

Trying to make the script below work for office365. 尝试使下面的脚本适用于office365。 Sends out an email but I cannot get the script to recognize the actual email text body (only the Subject line being sent). 发送一封电子邮件,但我无法获取脚本来识别实际的电子邮件文本正文(仅发送主题行)。 Below script worked for gmail. 以下脚本适用于gmail。 Any ideas where I need to modify? 有什么需要修改的想法吗?

Thanks! 谢谢!

 import smtplib, ssl port = 587 smtp_server = "smtp.office365.com" sender_email = "me@email.com" receiver_email = {'User1': 'user1@email.com'} password = "password" subject = input('Enter the subject line: ') message = input('Enter the message: ') email = """\\ Subject: %s %s """ % (subject, message) for key, value in receiver_email.items(): context = ssl.create_default_context() with smtplib.SMTP(smtp_server, port) as server: server.ehlo() # Can be omitted server.starttls(context=context) server.ehlo() # Can be omitted server.login(sender_email, password) server.sendmail(sender_email, value, email) server.quit() 

was missing a "\\n" in the email object. 在电子邮件对象中缺少“ \\ n”。 It now works. 它现在有效。

 email = """\\ Subject: %s\\n %s """ % (subject, message) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM