Skip to content

Instantly share code, notes, and snippets.

Created August 26, 2012 17:20
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mitchtech/3481781 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
import os
PASSWORD = "password"
def sendMail(to, subject, text, files=[]):
assert type(to)==list
assert type(files)==list
msg = MIMEMultipart()
msg['From'] = USERNAME
msg['To'] = COMMASPACE.join(to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach( MIMEText(text) )
for file in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(file,"rb").read() )
part.add_header('Content-Disposition', 'attachment; filename="%s"'
% os.path.basename(file))
server = smtplib.SMTP('')
server.sendmail(USERNAME, to, msg.as_string())
sendMail( [""],
"this is the subject",
"this is the body text of the email",
["photo.jpg","text_file.txt"] )
Copy link

really really thank you for your guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment