简体   繁体   中英

Python: How to pass email text body to Office365 Email

Trying to make the script below work for 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. 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. It now works.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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