gpt4 book ai didi

python - 在 python 中发送邮件时出错

转载 作者:行者123 更新时间:2023-11-28 21:11:25 25 4
gpt4 key购买 nike

pwd = "mypassword"
import smtplib

server = smtplib.SMTP('smtp.gmail.com')
server.ehlo()
server.starttls()
server.login("gvpcse113@gmail.com",pwd)

msg = "YOUR MESSAGE!"
server.sendmail("gvpcse113@gmail.com", "sender@xyz.com", msg)
server.quit()

我试过通过 python 发送邮件...
错误:

Traceback (most recent call last):
File "H:/my projects/PythonCourse/test_cont/mail_test4.py", line 4, in <module>
server = smtplib.SMTP('smtp.gmail.com')
File "C:\Python27\lib\smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "C:\Python27\lib\socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed

我正在通过代理连接
我在windows中通过cmd设置代理。请帮我解决这个问题。

更新:
我确定互联网连接:

import urllib2

def internet_on():
try:
response=urllib2.urlopen('https://www.google.co.in',timeout=1)
return True
except urllib2.URLError as err: pass
return False

print internet_on()

输出为 True

最佳答案

你的代码对我来说工作正常,所以它可能是连接设置。

尝试将服务器更改为:

server = smtplib.SMTP('64.233.184.108')

(就是smtp.gmail.com的IP地址,用来绕过DNS解析)

关于python - 在 python 中发送邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35362021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com