I'm new to python. i'm trying to send email using python. i have already enabled less secure app access and created app password but getting this error:
Traceback (most recent call last):
File "C:\My mask detection\xe1.py", line 11, in <module>
with smtplib.SMTP('smtplib.gmail.com',587)as smtp:
File "C:\Users\Adarsh C\AppData\Local\Programs\Thonny\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Adarsh C\AppData\Local\Programs\Thonny\lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Adarsh C\AppData\Local\Programs\Thonny\lib\smtplib.py", line 307, in _get_socket
self.source_address)
File "C:\Users\Adarsh C\AppData\Local\Programs\Thonny\lib\socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\Adarsh C\AppData\Local\Programs\Thonny\lib\socket.py", line 752, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
I don't understand what this error is referring to. i want to know where i have done wrong or do i want to do anything before i get in to code.
my code:
import smtplib
import os
with smtplib.SMTP('smtplib.gmail.com',587)as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login('helpdeskadhi@gmail.com','pnfnvboatmczopkn')
subject = "hello"
body = "Nice to meet you!"
msg = f'Subject: {subject}\n\n{body}'
smtp.sendmail('helpdeskadhi@gmail.com','helpdeskadhi@gmail.com',msg)
smtplib.SMTP('smtp.gmail.com',587)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.