Created
May 26, 2020 16:53
-
-
Save jamescalam/93d915e4de12e7f09834ae73bdf37299 to your computer and use it in GitHub Desktop.
Example code for sending an email via SMTP with TLS encryption in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
# initialize connection to our email server, we will use Outlook here | |
smtp = smtplib.SMTP('smtp-mail.outlook.com', port='587') | |
smtp.ehlo() # send the extended hello to our server | |
smtp.starttls() # tell server we want to communicate with TLS encryption | |
smtp.login('[email protected]', 'Password123') # login to our email server | |
# send our email message 'msg' to our boss | |
smtp.sendmail('[email protected]', | |
'[email protected]', | |
msg.as_string()) | |
smtp.quit() # finally, don't forget to close the connection |
The
msg
is missing.
Same boat for me, this was useful.
from email.message import EmailMessage
message = EmailMessage()
Another workaround is to replace msg.as_string() with your own string, ie. "hello world!"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
msg
is missing.