Last active
December 18, 2015 16:39
-
-
Save Guitsou/5812854 to your computer and use it in GitHub Desktop.
Envoyer un email avec une lib python... Source : http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script.htm
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 | |
SERVER = "localhost" | |
FROM = "[email protected]" | |
TO = ["[email protected]"] # must be a list | |
SUBJECT = "Hello!" | |
TEXT = "This message was sent with Python's smtplib." | |
# Prepare actual message | |
message = """\ | |
From: %s | |
To: %s | |
Subject: %s | |
%s | |
""" % (FROM, ", ".join(TO), SUBJECT, TEXT) | |
# Send the mail | |
server = smtplib.SMTP(SERVER) | |
server.sendmail(FROM, TO, message) | |
server.quit() |
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
## Variation. Source : http://www.nixtutor.com/linux/send-mail-through-gmail-with-python/ | |
import smtplib | |
fromaddr = '[email protected]' | |
toaddrs = '[email protected]' | |
msg = 'There was a terrible error that occured and I wanted you to know!' | |
# Credentials (if needed) | |
username = 'username' | |
password = 'password' | |
# The actual mail send | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.starttls() | |
server.login(username,password) | |
server.sendmail(fromaddr, toaddrs, msg) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment