'Udemy Day 32 Start Birthday Wisher – Email Won't Send
I'm working on Day 32 of Udemy 100 Days of Code for Python. Here is the code:
import smtplib
my_email = "[email protected]"
password = "password_goes_here"
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=my_email, password=password)
connection.sendmail(
from_addr=my_email,
to_addrs="[email protected]",
msg="Subject:Hello\n\nThis is the body of my email."
)
The problem is that it won't send. I've input the code several times and have removed the safety protocols for less secure apps. All emails and passwords have otherwise been tested. I get the following errors:
Traceback (most recent call last):
File "/Users/michaeldavis/Downloads/Birthday Wisher (Day 32) start/main.py", line 6, in <module>
with smtplib.SMTP("smtp.gmail.com") as connection:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
