Traceback (most recent call last):
File "/home/pi/0-kam-automail.py", line 131, in <module>
capture_image()
File "/home/pi/0-kam-automail.py", line 75, in capture_image
sendMail(data)
File "/home/pi/0-kam-automail.py", line 92, in sendMail
server = smtplib.SMTP('smtp.gmail.com', 587)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno -2] Name or service not known
and stops the script....
this is the part of the email function that I want to handel when error happen :
Code: Select all
def sendMail(data):
global texte
print texmed
mail = MIMEMultipart()
mail['Subject'] = str(texmed) # "Pictures from home"
mail['From'] = fromaddr
mail['To'] = toaddr
mail.attach(MIMEText(texte, 'plain'))
dat='%s.jpg'%data
attachment = open(dat, 'rb')
image=MIMEImage(attachment.read())
attachment.close()
mail.attach(image)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "pasword")
text = mail.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
movepic(data)
def movepic(data):
pic= '%s.jpg'%data
src = path+pic
dst = moveto+pic
shutil.move(src,dst)