Skip to content

Instantly share code, notes, and snippets.

@calston
Created January 30, 2014 15:07
Show Gist options
  • Save calston/8710552 to your computer and use it in GitHub Desktop.
Save calston/8710552 to your computer and use it in GitHub Desktop.
Send an email
#!/usr/bin/python
import sys, os, time
import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEImage import MIMEImage
def mailThings(subject, content, to):
struct = """<html>
<head></head>
<body style="font-family:arial,sans-serif;">
%s
</body>
</html>""" % content
me = 'whatever <whoever@wherever>'
cont = MIMEText(struct, 'html')
msg = MIMEMultipart('related')
msg['Subject'] = subject
msg['From'] = me
msg['To'] = ', '.join(to)
msg.attach(cont)
s = smtplib.SMTP()
s.connect()
s.sendmail(me, you, msg.as_string())
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment