Created
November 9, 2012 23:06
-
-
Save cntlscrut/4048909 to your computer and use it in GitHub Desktop.
Python email script for 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
#!/usr/bin/python | |
import smtplib | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email import Encoders | |
import os | |
gmail_user = "YOUREMAIL@WHATEVER.COM" | |
gmail_pwd = "PASSWORD" | |
def mail(to, subject, text): | |
msg = MIMEMultipart() | |
msg['From'] = gmail_user | |
msg['To'] = to | |
msg['Subject'] = subject | |
msg.attach(MIMEText(text)) | |
mailServer = smtplib.SMTP("smtp.gmail.com", 587) | |
mailServer.ehlo() | |
mailServer.starttls() | |
mailServer.ehlo() | |
mailServer.login(gmail_user, gmail_pwd) | |
mailServer.sendmail(gmail_user, to, msg.as_string()) | |
mailServer.close() | |
mail("RECIPIENT@WHATEVER.COM", | |
"SUBJECT", | |
"TEXT") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment