2014-06-06 9 views
5

Ich versuche, eine E-Mail über den Office365-Server zu senden. Die E-Mail wird ordnungsgemäß geliefert, jedoch wird die Nachricht nichtPython: SMTP mit TLS liefert keine Nachricht

Assistance am meisten angebracht

geschätzt
import smtplib 

to = "[email protected]" 
office365_user = '[email protected]' 
office365_pwd = 'password' 

smtpserver = smtplib.SMTP("smtp.office365.com",587) 
smtpserver.ehlo() 
smtpserver.starttls() 
smtpserver.ehlo() 
smtpserver.login(office365_user,office365_pwd) 
msg = "This is a test email \n" 
smtpserver.sendmail(office365_user, to, msg) 
smtpserver.close() 

Antwort

4

Ihre Nachricht ist keine gültige E-Mail-Nachricht, die aus einem Kopf und einem Körper besteht. Probieren Sie etwas wie folgt aus:

msg = """From: <[email protected]> 
To: <[email protected]> 
Subject: foo 

This is a test email 
""" 
1

Betrachten Sie die Nachricht in der gleichen Weise wie die Python documentation Konstruktion.

from email.mime.text import MIMEText 

msg = MIMEText("This is a test email") 
msg['Subject'] = 'Email Subject' 
msg['From'] = '[email protected]' 
msg['To'] = '[email protected]' 

Auch bin ich über die Verwendung von smtpserver.close() nicht sicher. Es scheint der richtige Weg ist smtpserver.quit().

Verwandte Themen