Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import smtplib
- from email.mime.image import MIMEImage
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- addr_from = "*********g@gmail.com"
- addr_to = "********@gmail.com"
- password = "************"
- img_data = open("image.jpg", 'rb').read()
- msg = MIMEMultipart()
- msg['From'] = addr_from
- msg['To'] = addr_to
- msg['Subject'] = "Тема"
- text1 = ("Текст письма")
- msg.attach(MIMEText(text1, 'plain'))
- #attach photo
- try:
- image = MIMEImage(img_data)
- image.add_header('Content-Disposition', 'attachment', filename="image.jpg")
- msg.attach(image)
- except Exception as e:
- print(e)
- smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
- smtpObj.starttls()
- smtpObj.login(addr_from, password)
- smtpObj.send_message(msg)
- smtpObj.quit()
- print("Mailed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement