Created
March 30, 2014 14:54
-
-
Save mshuffett/9873851 to your computer and use it in GitHub Desktop.
Send email using Gmail
This file contains 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 | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEText import MIMEText | |
def sendmail(message, subject='subject', username='username', password='password', address='reciever'): | |
msg = MIMEMultipart() | |
msg['From'] = username | |
msg['To'] = address | |
msg['Subject'] = subject | |
msg.attach(MIMEText(message, 'plain')) | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.starttls() | |
server.login(username, password) | |
text = msg.as_string() | |
server.sendmail(username, address, text) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment