Skip to content

Instantly share code, notes, and snippets.

@makersm
Created May 30, 2016 05:36
Show Gist options
  • Save makersm/9be40c332aaa5505037710946dff8970 to your computer and use it in GitHub Desktop.
Save makersm/9be40c332aaa5505037710946dff8970 to your computer and use it in GitHub Desktop.
mail send with files
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