【问题标题】:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for . (_ssl.c:1125)SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:主机名不匹配,证书对 无效。 (_ssl.c:1125)
【发布时间】:2022-10-15 16:28:03
【问题描述】:

我正在尝试使用 python SMTP 服务器发送电子邮件。当我将我的个人凭据与“Gmail SMTP 服务器和端口为 587”一起使用时,我能够将消息发送给收件人,但是当我使用客户端凭据时,我得到:

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:主机名不匹配,证书对“示例服务器”无效。 (_ssl.c:1125)。

有人可以帮我吗?

下面是我的代码:

import smtplib
import ssl
import certifi

port = 587 
smtp_server = "test@server.com"
sender = "example@sender.com"
recipient = "example@receiver.com"
sender_password = "abcdefghij"
message = "Trying to send an email"

SSL_context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
    server.starttls(context=SSL_context)
    server.login(sender, sender_password)
    server.sendmail(sender, recipient, message)

【问题讨论】:

    标签: python email ssl-certificate certificate smtplib


    【解决方案1】:

    试一试如下, 转到您下载 python 的 Python 文件夹并安装 Install Certificates.command 然后再次运行代码

    【讨论】:

      猜你喜欢
      • 2018-07-29
      • 2017-06-01
      • 2017-02-05
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 2015-12-21
      • 2022-01-11
      相关资源
      最近更新 更多