我正在尝试从python脚本发送电子邮件。我正在使用这个例子,但不知何故,代码继续运行,并没有返回任何东西。你知道吗
import smtplib
to = 'receiver'
gmail_user = 'username'
gmail_pwd = 'password'
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:testing \n'
print header
msg = header + '\n this is test msg from mkyong.com \n\n'
smtpserver.sendmail(gmail_user, to, msg)
print 'done!'
smtpserver.close()
我还启用了允许在google帐户中使用不太安全的应用程序。我在中断此代码时遇到的错误是:
Traceback (most recent call last):
File "/Users/kgandh003c/PycharmProjects/kandarp_exercise/kandarp.py", line 6, in <module>
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 60] Operation timed out
请让我知道什么可能是错误的,如果有人面对这个问题。你知道吗
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐