Skip to content

Instantly share code, notes, and snippets.

@makersm
Created May 28, 2016 10:53
Show Gist options
  • Save makersm/1f0de1feab44c5d3694627c8e2a14a07 to your computer and use it in GitHub Desktop.
Save makersm/1f0de1feab44c5d3694627c8e2a14a07 to your computer and use it in GitHub Desktop.
mail send with image
from smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
mail = MIMEMultipart()
mail['Subject'] = 'this is title'
fp = open(file, 'rb') # only image works
mail.attach(MIMEImage(fp.read()))
fp.close()
mail.attach(MIMEText('this is content'))
mailserver = smtplib.SMTP('localhost')
mailserver.sendmail(sender, recipient, title, mail.as_string())
mailserver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment