I'm creating a program to send e-mails using python. Here's my code:
import os
import smtplib
from email.message import EmailMessage
EMAIL_ADDRESS = os.environ.get("xxx@gmail.com")
EMAIL_PASSWORD = os.environ.get("xxxXXxxx")
msg = EmailMessage()
msg['Subject'] = 'Python'
msg['From'] = EMAIL_ADDRESS
msg['To'] = EMAIL_ADDRESS
msg.set_content('Mail fom Python')
msg.add_alternative("""\
<!DOCTYPE html>
<html>
<body>
<h1 style="color:SlateGray;">This is an HTML Email!</h1>
</body>
</html>
""", subtype='html')
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
A minute after executing, I see the following in the terminal:
Traceback (most recent call last):
File "multimail.py", line 24, in <module>
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
File "/usr/local/lib/python3.7/smtplib.py", line 1031, in __init__
source_address)
File "/usr/local/lib/python3.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.7/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/local/lib/python3.7/smtplib.py", line 1037, in _get_socket
self.source_address)
File "/usr/local/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address
I've tried to understand the other answers to this question, but I'm a noob so can anyone help me with my specific code?