【问题标题】:Python connetion to smtp port 465 server failsPython 连接到 smtp 端口 465 服务器失败
【发布时间】:2020-10-22 19:26:06
【问题描述】:

这是我的脚本:

import smtplib
from socket import gaierror

port = 465 
smtp_server = "my_server.com"
login = "my_login_name.com"
password = "my_pass"

sender = "my_email.com"
receiver = "receiver_email.com"

message = f"""Subject: Hi Mailtrap
To: {receiver}
From: {sender}

This is my first message with Python."""

try:
    with smtplib.SMTP(smtp_server, port) as server:
        server.login(login, password)
        server.sendmail(sender, receiver, message)

    print('Sent')
except (gaierror, ConnectionRefusedError):
    print('Failed to connect to the server. Bad connection settings?')
except smtplib.SMTPServerDisconnected:
    print('Failed to connect to the server. Wrong user/password?')
except smtplib.SMTPException as e:
    print('SMTP error occurred: ' + str(e))

我正在尝试发送简单的电子邮件,但我收到了回复消息:Failed to connect to the server. Wrong user/password?。我想与服务器的连接存在一些问题。端口号、SMTP 服务器地址、登录名和密码正确。我也尝试使用我的 google 电子邮件帐户和 google SMTP 服务器,但回答相同。缺什么?谢谢!

【问题讨论】:

    标签: python smtp


    【解决方案1】:

    尝试使用 ssl smtplib.SMTP_SSL(host,465)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      • 2020-03-20
      • 2014-03-08
      • 2015-12-27
      相关资源
      最近更新 更多