Created
May 30, 2016 05:36
-
-
Save makersm/9be40c332aaa5505037710946dff8970 to your computer and use it in GitHub Desktop.
mail send with files
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
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.application import MIMEApplication | |
mail = MIMEMultipart() | |
mail['Subject'] = title | |
mail.preamble = 'This is a multi-part message in MIME format' | |
mail.attach(MIMEImage(message)) | |
file_part = MIMEApplication(open(file, "rb").read(), name=filename) | |
file_part.add_header('Content-Disposition', 'attachment', filename=filename) | |
mail.attach(file_part) | |
mail_server = smtplib.SMTP('localhost') | |
mail_server.sendmail(sender, recipient, title, mail.as_string()) | |
mail_server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment