SMTP mail problem
Posted: Sat Sep 14, 2019 11:38 pm
I am trying to send and email from a python script and I am getting some errors I don't understand. I am running Stretch so I can use SMTP. Any idea what is going one? Also why is there the smtp.conf file if you are entering the server information, email address and password in the code?
Here is my code:
Here are the errors and output I get.:
>>> %Run testemail.py
import
Traceback (most recent call last):
File "/home/pi/Documents/testemail.py", line 3, in <module>
server = smtplib.SMTP_SSL('smtp.gmail.com', 485)
File "/usr/lib/python3.5/smtplib.py", line 1021, in __init__
source_address)
File "/usr/lib/python3.5/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.5/smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.5/smtplib.py", line 1027, in _get_socket
self.source_address)
File "/usr/lib/python3.5/socket.py", line 712, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 703, in create_connection
sock.connect(sa)
OSError: [Errno 113] No route to host
>>>
Here is my code:
Code: Select all
import smtplib, ssl
print('import')
server = smtplib.SMTP_SSL('smtp.gmail.com', 485)
#server = smtplib.SMTP('smtp.gmail.com', 587)
#server.ehlo()
#server.starttls()
print('line one')
server.login('myemail@gmail.com','password')
print('line two')
msg='Pi test'
print('mesage is ' + msg)
server.sendmail('myemailgmail.com','phonenumber@txt.att.net',msg)
server.quit()>>> %Run testemail.py
import
Traceback (most recent call last):
File "/home/pi/Documents/testemail.py", line 3, in <module>
server = smtplib.SMTP_SSL('smtp.gmail.com', 485)
File "/usr/lib/python3.5/smtplib.py", line 1021, in __init__
source_address)
File "/usr/lib/python3.5/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.5/smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.5/smtplib.py", line 1027, in _get_socket
self.source_address)
File "/usr/lib/python3.5/socket.py", line 712, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 703, in create_connection
sock.connect(sa)
OSError: [Errno 113] No route to host
>>>