Skip to content

Instantly share code, notes, and snippets.

@khibma
Last active December 28, 2015 10:19
Show Gist options
  • Save khibma/7485344 to your computer and use it in GitHub Desktop.
Save khibma/7485344 to your computer and use it in GitHub Desktop.
Send email
def sendEmail(content, images):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
FROM = 'FROMemail@email.com'
TO = 'TOemail@email.com'
msg = MIMEMultipart()
msg['From'] = FROM
msg['To'] = TO
msg['Subject'] = "EMAIL SUBJECT LINE"
#MIMEText('<html><body><b>hello</b><br><img src="cid:graph"><br></body></html>', 'html')
msgText = MIMEText(content, 'html')
msg.attach(msgText)
if images is not None:
for k, v in images.iteritems():
fp = open(v, 'rb')
img = MIMEImage(fp.read())
fp.close()
#img.add_header('Content-ID', '<graph>')
img.add_header('Content-ID', '<{}>'.format(str(k)))
msg.attach(img)
# Send the mail
server = smtplib.SMTP("EMAILSERVER.COM")
server.sendmail(FROM, TO, msg.as_string())
server.quit()
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment