Skip to content

Instantly share code, notes, and snippets.

@jakl
Created August 8, 2011 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakl/1132612 to your computer and use it in GitHub Desktop.
Save jakl/1132612 to your computer and use it in GitHub Desktop.
Send an email using python and your gmail smtp
#!/usr/bin/python
import os
import smtplib
import mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def sendMail(subject, text):
gmailUser = 'jediknight304@gmail.com'
gmailPassword = 'like I|d give you this that easily....'
recipient = 'james.ross.koval@gmail.com'
msg = MIMEMultipart()
msg['From'] = gmailUser
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText(text, 'html'))
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
mailServer.sendmail(gmailUser, recipient, msg.as_string())
mailServer.close()
print('Sent email to %s' % recipient)
sendMail('this is whack', '<head>this is the head</head><body>and here comes <a href="google.com">the hook!</a></body>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment