I'm using this code to send mail. When i add part for attaching the picture i get error written in subject.
I dont quite understand what this message means. Is there something wrong with picture type (jpg) ?
Code: Select all
import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import datetime
# sender
to = 'mymail@mail.com'
gmail_user = 'user@gmail.com'
gmail_password = '12345'
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_password)
today = datetime.date.today()
#add picture
fp = open(file, 'picture.jpg')
img = MIMEImage(fp.read())
fp.close()
msg.attach(img)
# reciever
arg='ip route list'
p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
data = p.communicate()
split_data = data[0].split()
ipaddr = split_data[split_data.index('src')+1]
my_ip = 'IP : %s' % ipaddr
msg = MIMEText(my_ip)
msg['Subject'] = 'Test message %s' % today.strftime('%b %d %Y')
msg['From'] = 'tester'
msg['To'] = to
smtpserver.sendmail(gmail_user, [to], msg.as_string())
smtpserver.quit()Thank you in advance for your answer !
PIN