我可以从一个Gmail帐户发送到另一个Gmail帐户,从一个Outlook帐户发送到另一个Outlook帐户。 但是当我尝试将邮件从outlook发送到gmail时,我遇到了问题。
这是代码
import smtplib
content ='example email stuff here'
email='xyz@outlook.com'
password="password"
fromemail="xyz@outlook.com"
receive="abc@gmail.com"
mail=smtplib.SMTP('smtp-mail.outlook.com',587)
mail.ehlo()
mail.starttls()
mail.login(email,password)
mail.sendmail(fromemail,receive,content)
mail.close()
当我运行脚本时,我收到以下错误
Traceback (most recent call last):
File "smtp_google.py", line 7, in <module>
mail=smtplib.SMTP('smtp-mail.outlook.com',587)
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 575, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after
a period of time, or established connection failed because connected host has failed to respond
答案 0 :(得分:0)
解决方案1:
尝试给予超时:
mail=smtplib.SMTP('smtp-mail.outlook.com',587)
as
mail=smtplib.SMTP('smtp-mail.outlook.com',587, timeout=120)
或尝试通过SSL而不是TLS / STARTTLS进行连接
mail=smtplib.SMTP_SSL('smtp-mail.outlook.com',587)
解决方案2: 您的电子邮件帐户必须允许smtp,默认情况下不一定启用。您可以按照此处enable smtp authentication
中给出的步骤尝试更改设置