Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import email
- import smtplib
- import mimetypes
- from email.MIMEText import MIMEText
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEBase import MIMEBase
- from email import encoders
- from_addr = 'ms015a.2014@gmail.com'
- to_addr = 'ms015a.2014@gmail.com'
- subject_header = 'Subject: Testing SMTP'
- attachment = 'disk_report.pdf'
- body = '''
- This message sends a PDF attachment '''
- username = 'ms015a.2014'
- password = 'pythoniscool'
- m = MIMEMultipart()
- m["To"] = to_addr
- m["From"] = from_addr
- m["Subject"] = subject_header
- ctype, encoding = mimetypes.guess_type(attachment)
- print ctype, encoding
- maintype, subtype = ctype.split('/', 1)
- print maintype, subtype
- m.attach(MIMEText(body))
- pdffile = open(attachment, "rb")
- msg = MIMEBase(maintype, subtype)
- msg.set_payload(fp.read())
- pdffile.close()
- encoders.encode_base64(msg)
- msg.add_header("Content-Disposition", "attachment", filename=attachment)
- m.attach(msg)
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username, password)
- server.sendmail(fromaddr, toaddr, m.as_string())
- server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement