import sys
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
msg = MIMEMultipart()
msg['Subject'] = 'Тема письма'
msg['From'] = 'sender@mail.ru'
part = MIMEText('Текст письма\n')
msg.attach(part)
part = MIMEApplication(open('image.jpg', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename='image.jpg')
msg.attach(part)
server = smtplib.SMTP('smtp.mail.ru:587')
server.ehlo()
server.starttls()
server.login('sender@mail.ru', 'password')
server.sendmail(msg['From'], ['recipient@mail.ru'], msg.as_string())