我使用这个python脚本从raspberry pi发送电子邮件,文件名是email_test.py 导入smtplib 导入字符串
HOST = "smtp.gmail.com"
SUBJECT = "test"
TO = "receiving mail @gmail.com"
FROM = "mail used for sending@gmail.com"
text = "this is a test from the pi"
BODY = string.join(("from: %s" %FROM, "to: %s" %TO,"Subject: %s" %SUBJECT, " ", text), "\r\n")
s = smtplib.SMTP("smtp.gmail.com",587)
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.login("mail used for sending@gmail.com", "password")
s.sendmail(FROM,[TO],BODY)
s.quit
它抛出了这个错误
Traceback (most recent call last):
File "email_test.py", line 10, in <module>
s = smtplib.SMTP("smtp.gmail.com",587)
File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
有人可以帮忙吗?
答案 0 :(得分:1)
对不起,这是wifi的一个问题,我刚刚删除了wifi加密狗并把它放回去,一切运转良好