Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to clear all data in MIMEBase (email module)
- 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
- def sendMail(to, subject, text, files=[],server="smtp.gmail.com:587"):
- assert type(to)==list
- assert type(files)==list
- fro = "psaoflamand@live.com>"
- msg = MIMEMultipart()
- msg['From'] = fro
- msg['To'] = COMMASPACE.join(to)
- msg['Date'] = formatdate(localtime=True)
- msg['Subject'] = subject
- msg.attach( MIMEText(text) )
- a=0
- username = 'psaoflamand@gmail.com'
- password = 'pass'
- # The actual mail send
- smtp = smtplib.SMTP(server)
- smtp.starttls()
- smtp.login(username,password)
- for file in files:
- a+=1
- print a
- part = MIMEBase('application', "octet-stream")
- part.set_payload( open(file,"rb").read() )
- Encoders.encode_base64(part)
- part.add_header('Content-Disposition', 'attachment; filename="%s"'
- % os.path.basename(file))
- msg.attach(part)
- if a==21:
- smtp.sendmail(fro, to, msg.as_string() )
- a=0
- print 'sent'
- smtp.quit()
- sendMail(
- ["psaoflamand@live.com"],
- "hello","cheers",
- ["Thousands of one megabyte files"]
Add Comment
Please, Sign In to add comment