Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from smtplib import SMTP_SSL
- import email
- from email.mime.multipart import MIMEMultipart
- from email.mime.base import MIMEBase
- from email.mime.text import MIMEText
- from email import encoders
- import os
- #filepath must be like this (from the very beginning directory): 'C://dir/dir/dir/dir/filename.jpg' or any other
- #filename extension. for example .doc
- filepath = 'C://Users/олег/Downloads/long_legs_by_carolelalibre-d5l5r75.jpg'
- basename = os.path.basename(filepath)
- address = 'sender_email'
- #Compose attachment
- part = MIMEBase('application', "octet-stream")
- part.set_payload(open(filepath, "rb").read())
- encoders.encode_base64(part) #i think this '64' stuff stands for your Win64 or 32, i dont know for sure
- part.add_header('Content-Disposition', 'attachment; filename = "%s"' % basename)
- #Compose message
- msg = MIMEMultipart()
- msg['From'] = 'sender_email'
- msg['To'] = 'receiver_email'
- msg.attach(part)
- #Send mail
- smtp = smtplib.SMTP('smtp.mail.ru', 25) #25 is the port of smtp.mail.ru
- smtp.ehlo()
- smtp.starttls()
- smtp.login(address, "sender's_email_password")
- smtp.sendmail(address, address, msg.as_string())
- print('Executed')
- smtp.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement