Last active
August 29, 2015 14:08
-
-
Save alexwoolford/1cecafe8a74ff9ebe4ef to your computer and use it in GitHub Desktop.
Send from 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/env python | |
# suggested gmail code for StackOverflow question: http://stackoverflow.com/questions/26772416/how-to-write-a-program-to-check-website-for-a-string | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.application import MIMEApplication | |
from email.mime.multipart import MIMEMultipart | |
def sendEmail(fileName, emailTo): | |
msg = MIMEMultipart() | |
emailFrom = "[email protected]" | |
username = emailFrom | |
password = "passw0rd" | |
smtpServer = 'smtp.gmail.com' | |
msg['Subject'] = '[insert your subject here]' | |
msg['From'] = emailFrom | |
msg['To'] = emailTo | |
msg.attach(MIMEText("""Dear [person].\n\nHere is the file you've been waiting for.\n\nRegards,\n\nAnon""")) | |
attachm = MIMEApplication(open(fileName,"rb").read()) | |
attachm.add_header('Content-Disposition', 'attachment', filename = fileName) | |
msg.attach(attachm) | |
server = smtplib.SMTP(smtpServer, 587) | |
server.set_debuglevel(1) | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login(username, password) | |
server.sendmail(emailFrom, [emailTo], msg.as_string()) | |
server.close() | |
if __name__ == "__main__": | |
sendEmail('some_attachment.txt', '[email protected]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment