Created
May 28, 2016 10:53
-
-
Save makersm/1f0de1feab44c5d3694627c8e2a14a07 to your computer and use it in GitHub Desktop.
mail send with image
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
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