尝试通过 python 发送电子邮件并收到套接字错误

Trying to send email through python and getting error with socket

这是我的代码

import smtplib
from datetime import datetime

print("Sending Mail")
with smtplib.SMTP('smpt.gmail.com', 587) as smtp:
    smtp.ehlo()
    smtp.starttls()
    smtp.ehlo()
    
    smtp.login('gmail', 'password')
    print("Logged In")

    subject = "Current Time: " + datetime.now.strftime("%d/%m/%Y %H:%M:%S")

    smtp.sendmail('myemail@gmail.com', 'myemail@gmail.com', "hello")
    print("Sent Email")

我正在尝试使用 smtplib 通过 gmail 发送电子邮件,这是我收到的错误:

Sending Mail
Traceback (most recent call last):
  File "c:/Users/12488/Downloads/Key Logger/keylog.py", line 43, in <module>
    with smtplib.SMTP('smpt.gmail.com', 587) as smtp:
  File "C:\Users488\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Users488\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Users488\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 308, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "C:\Users488\AppData\Local\Programs\Python\Python38\lib\socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Users488\AppData\Local\Programs\Python\Python38\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

我确保在 gmail 上检查了安全性较低的设备,但我还没有尝试过互联网上的所有解决方案,因为我是 python 的新手,这是我第一次使用 smtp,但我没有得到很多,我认为这与套接字有关,因为这是我读过的另一个流行的 python 模块,但我对此了解不多,我不确定是否有人可以简化错误并像我 5 岁的孩子一样向我解释,将不胜感激。

您使用的域不正确,DNS 服务器未解析该域。

smpt.gmail.com

应该是:

smtp.gmail.com