【问题标题】:smtplib.SMTPConnectError: (421, b'Cannot connect to SMTP server 2a00:1450:400c:c09::6c (2a00:1450:400c:c09::6c:25), connect error 10060') [duplicate]smtplib.SMTPConnectError: (421, b'无法连接到 SMTP 服务器 2a00:1450:400c:c09::6c (2a00:1450:400c:c09::6c:25),连接错误 10060') [重复]
【发布时间】:2020-10-24 10:10:20
【问题描述】:

我想知道为什么这段代码不起作用。我在 VSCode,python 3.8.0-32bit。我不知道这个问题是来自代码还是来自我应该对我的 gmail 执行的操作。能不能请教一下


sender_email = input(str("enter your email address: "))
password = input(str("enter your password: "))
rec_email = input(str("enter the email address to whom you want to send the message: "))
message = str("message envoyé avec python")
print(".")
server = smtplib.SMTP('smtp.gmail.com')
print(".")
server.starttls()
print(".")
server.login(sender_email,password)
print("login success")
server.sendmail(sender_email,rec_email,message)
print("email has be sent to", rec_email)```
And python sends me back:
```Windows PowerShell
Copyright (C) Microsoft Corporation. Tous droits réservés.

Testez le nouveau système multiplateforme PowerShell https://aka.ms/pscore6

PS C:\Users\*************> & C:/Users/evain/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/evain/OneDrive/Bureau/mail.py
enter your email address: ev******************4@gmail.com
enter your password: **********************
enter the email address to whom you want to send the message: ma*****************1@gmail.com
.
Traceback (most recent call last):
  File "c:/Users/***********/OneDrive/Bureau/mail.py", line 8, in <module>
    server = smtplib.SMTP('smtp.gmail.com')
  File "C:\Users\***********\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 256, in __init__
    raise SMTPConnectError(code, msg)
smtplib.SMTPConnectError: (421, b'Cannot connect to SMTP server 2a00:1450:400c:c09::6c (2a00:1450:400c:c09::6c:25), connect error 10060')```

【问题讨论】:

  • 这能回答你的问题吗? Failing to send email with the Python example
  • 您的 PC 几乎可以肯定没有权限连接到端口 25 上的任何位置,除了您自己的 ISP 的邮件服务器(即使这样,您也可能需要进行身份验证)。垃圾邮件发送者已经在游泳池里撒尿 25 年了。你不想在那里游泳。
  • 另外,您发送的邮件必须是正确构造的 SMTP 邮件,而不是随机字符串。

标签: python email smtplib


【解决方案1】:

我的 Outlook 设置显示服务器“smtp.gmail.com”使用端口 465 和 SSL/TLS 加密。因此我使用: 服务器 = smtplib.SMTP_SSL(‘smtp.gmail.com’) 代替: 服务器 = smtplib.SMTP(‘smtp.gmail.com’) server.starttls()。 作为这个主题的新手,我在How to send an email with Gmail as provider using Python? 下找到了这个解决方案。

【讨论】:

  • 抱歉,我看不到问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-20
  • 2017-08-16
  • 1970-01-01
相关资源
最近更新 更多