Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import os
- import smtplib
- from email.mime.text import MIMEText
- from email.mime.multipart import MIMEMultipart
- from email.mime.base import MIMEBase
- from email import encoders
- email_user = 'testing04032016@gmail.com'
- email_password = 'Testing@0403'
- email_send = 'rajjnagar@gmail.com'
- subject = 'testtting'
- msg = MIMEMultipart()
- msg['From'] = email_user
- msg['To'] = email_send
- msg['Subject'] = subject
- body = 'Hi there, sending this email from Python!'
- msg.attach(MIMEText(body,'plain'))
- filename = "C:\\Users\\lvura_000\\Downloads\\maxresdefault.jpg"
- attachment = open(filename,'rb')
- name=os.path.basename(filename)
- part = MIMEBase('application','octet-stream')
- part.set_payload((attachment).read())
- encoders.encode_base64(part)
- part.add_header('Content-Disposition',"attachment; filename= "+name)
- msg.attach(part)
- text = msg.as_string()
- try:
- server = smtplib.SMTP('smtp.gmail.com',587)
- server.starttls()
- server.login(email_user,email_password)
- server.sendmail(email_user,email_send,text)
- print ("Successfully sent email")
- server.quit()
- except SMTPException:
- print ("Error: unable to send email")
Add Comment
Please, Sign In to add comment