SMTP 发送:“getaddrinfo 失败”

问题描述

import smtplib

def sendEmail(receiver,subject,message):
    server = smtplib.SMTP('smtp.gamil.com',587)
    server.ehlo()
    server.starttls()
    server.login("botsinhala@gmail.com",password)
    server.sendmail("botsinhala@gmail.com",receiver,message)
    
    print("succesful")

sendEmail("gadjetrathnayake@gmail.com","testing bot","Hi,This is a testing message i'm sending to you.")

以上代码产生以下错误。我的操作系统是 Windows 10。

Traceback (most recent call last):
  File "D:/MY CHANNEL/python tricks/Email bot 1/tttttttttttttttttttttttt.py",line 17,in <module>
    sendEmail("andrewhawkins@gmail.com",This is a testing message i'm sending to you.")
  File "D:/MY CHANNEL/python tricks/Email bot 1/tttttttttttttttttttttttt.py",line 5,in sendEmail
    server = smtplib.SMTP('smtp.gamil.com',587)
  File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py",line 251,in __init__
    (code,msg) = self.connect(host,port)
  File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py",line 336,in connect
    self.sock = self._get_socket(host,port,self.timeout)
  File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py",line 307,in _get_socket
    self.source_address)
  File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\socket.py",line 707,in create_connection
    for res in getaddrinfo(host,SOCK_STREAM):
  File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\socket.py",line 748,in getaddrinfo
    for res in _socket.getaddrinfo(host,family,type,proto,flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

我该如何解决这个错误

解决方法

ServiceBase 替换为 smtp.gamil.com

smtp.gmail.com (2021-01-07T13:08+00:00) 没有 A/AAAA 记录。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...