I am trying to send emails using python and smptplib but it shows some errors the following is my code:
import smtplib,ssl
port = 456
password = input("enter your password : ")
email_id = input("enter your email adress: ")
print("creating connection...")
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com",port,context=context) as server:
server.login(email_id,password)
Traceback (most recent call last):
File "/Users/rijilvarghese/Documents/email.py/newemail.py", line 9, in <module>
with smtplib.SMTP_SSL("smtp.gmail.com",port,context=context) as server:
File "/opt/anaconda3/lib/python3.7/smtplib.py", line 1031, in __init__
source_address)
File "/opt/anaconda3/lib/python3.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/opt/anaconda3/lib/python3.7/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/opt/anaconda3/lib/python3.7/smtplib.py", line 1037, in _get_socket
self.source_address)
File "/opt/anaconda3/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/opt/anaconda3/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
OSError: [Errno 65] No route to host
this Are the errors,What should i do?
Related
All lines starting from line all return an error Errno 10060 or an error Errno 10061:
import smtplib
server = smtplib.SMTP('smtp.gmail.com:465')
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer = smtplib.SMTP("smtp.gmail.com", 465)
mailServer = smtplib.SMTP("smtp.mail.ru", 25)
mailServer = smtplib.SMTP("smtp.mail.ru", 2525)
Could you help? I must be missing something trivial... Error messages in full:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Use smtplib.SMTP_SSL() for a TLS connection.
There is nothing wrong with all commands below; my issue is indeed caused by IP restrictions. Thanks for all your answers.
Or Use server = smtplib.SMTP('smtp.gmail.com:25') for normal connection
and if you want tls from port 25, simply add
server.starttls()
after the first line.
ps: since port 25 is default, the following is equivalent:
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()
I tried to write an email using python's smtplib module. Here is my code as well as the error displayed below. Thank you!
import smtplib
my_email = 'xxxxxxxxxxx#hotmail.com'
password = 'xxxxxxxxxx'
# I hid my email and password here
with smtplib.SMTP('outlook.office365.com') as connection:
connection.starttls()
connection.login(user=my_email, password=password)
connection.sendmail(from_addr=my_email, to_addrs=my_email, msg='helloworld')
/usr/local/bin/python3 "/Users/guanhongjiang/PycharmProjects/pythonProject/Birthday Wisher (Day 32) start/main.py"
Traceback (most recent call last):
File "/Users/guanhongjiang/PycharmProjects/pythonProject/Birthday Wisher (Day 32) start/main.py", line 6, in <module>
with smtplib.SMTP('outlook.office365.com') as connection:
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 845, in create_connection
raise err
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 833, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
I have my Flask application that sends mail. I have specified my SMTP server and ports inside the application. This works perfectly fine in my local machine. I want to run this application inside the container. I have exposed the flask's default port 5000 and maps the port with the local machine while running the container. But it fails to send the mail, The error which I am getting is as follows.
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/ATEC-C7cLNkeV/lib/python3.8/site-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/ATEC/application/routes.py", line 107, in weeklymail
mail.send(msg)
File "/root/.local/share/virtualenvs/ATEC-C7cLNkeV/lib/python3.8/site-packages/flask_mail.py", line 491, in send
with self.connect() as connection:
File "/root/.local/share/virtualenvs/ATEC-C7cLNkeV/lib/python3.8/site-packages/flask_mail.py", line 144, in __enter__
self.host = self.configure_host()
File "/root/.local/share/virtualenvs/ATEC-C7cLNkeV/lib/python3.8/site-packages/flask_mail.py", line 156, in configure_host
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
File "/usr/local/lib/python3.8/smtplib.py", line 1034, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/usr/local/lib/python3.8/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.8/smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/local/lib/python3.8/smtplib.py", line 1040, in _get_socket
new_socket = socket.create_connection((host, port), timeout,
File "/usr/local/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/local/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out
I'm trying to send an email using a corporate email address with smtplib in Python 3.7.
Here's my code:
import smtplib
from email.mime.text import MIMEText
from_addr='myEmail#corporate.com'
to_addr='myEmail#corporate.com'
server = smtplib.SMTP('corporateServer', 'port')
server.starttls()
msg = MIMEText('send my python', 'plain', 'utf-8')
server.sendmail(from_addr, to_addr, msg.as_string())
server.quit()
Error:
Traceback (most recent call last): File "script.py", line 51, in
<module>
server = smtplib.SMTP(smtpServer, 25) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py",
line 251, in __init__
(code, msg) = self.connect(host, port) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py",
line 336, in connect
self.sock = self._get_socket(host, port, self.timeout) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py",
line 307, in _get_socket
self.source_address) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 727, in create_connection
raise err File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa) TimeoutError: [Errno 60] Operation timed out
All lines starting from line all return an error Errno 10060 or an error Errno 10061:
import smtplib
server = smtplib.SMTP('smtp.gmail.com:465')
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer = smtplib.SMTP("smtp.gmail.com", 465)
mailServer = smtplib.SMTP("smtp.mail.ru", 25)
mailServer = smtplib.SMTP("smtp.mail.ru", 2525)
Could you help? I must be missing something trivial... Error messages in full:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Use smtplib.SMTP_SSL() for a TLS connection.
There is nothing wrong with all commands below; my issue is indeed caused by IP restrictions. Thanks for all your answers.
Or Use server = smtplib.SMTP('smtp.gmail.com:25') for normal connection
and if you want tls from port 25, simply add
server.starttls()
after the first line.
ps: since port 25 is default, the following is equivalent:
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()