gpt4 book ai didi

python-3.x - 从 AWS 使用 SES 发送电子邮件时出现 "Connection unexpectedly closed"错误

转载 作者:行者123 更新时间:2023-12-04 12:59:21 37 4
gpt4 key购买 nike

因此,我正在尝试使用 SMTP 和 AWS 向自己发送电子邮件。我在配置中使用的电子邮件经过验证,因为我仍在 SES 中使用沙箱模式。在运行脚本时,我不断收到错误 Connection unexpectedly closed甚至面团我试图与 OpenSSL 连接并且它已连接但它显示了 Didn't find STARTTLS in server response, trying anyway...连接后出错。

这是我的代码:

MAIL = {}
MAIL['USERNAME'] = 'AKIAXARHTFGFKCDAO7PD'
MAIL['PASSWORD'] = 'BE0tXPq8wteiKZYtgD2TgtfFTGhgFGOhUp3F0lG0uqn'
MAIL['HOST'] = 'email-smtp.eu-central-1.amazonaws.com'
MAIL['PORT'] = 465


# Set user code
code = random.randrange(000000, 999999)
# Send email to user
print(code)
print(current_user.email)
msg = MIMEMultipart('alternative')
msg['Subject'] = 'Ruby - Verification code'
msg['From'] = 'amng835@gmail.com'
msg['To'] = current_user.email
msg.attach(MIMEText(f'Your verification code is: {code}', 'plain'))
try:
server = smtplib.SMTP(MAIL['HOST'], MAIL['PORT'])
server.ehlo()
server.starttls()
server.ehlo()
server.login(MAIL('MAIL_USERNAME'), MAIL('MAIL_PASSWORD'))
server.sendmail('amng835@gmail.com', current_user.email, msg.as_string())
server.close()
except Exception as error:
print('Failed to send message to user')
print(error)

OpenSSL 输出:

命令:
openssl s_client -connect email-smtp.eu-central-1.amazonaws.com:465 -starttls smtp

输出:
CONNECTED(00000005)
Didn't find STARTTLS in server response, trying anyway...
write:errno=0
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 372 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---

我的文档来源:
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-using-smtp.html

最佳答案

端口 465 似乎有一些问题。将代码更改为下面,它会正常工作。

MAIL['PORT'] = 587

关于python-3.x - 从 AWS 使用 SES 发送电子邮件时出现 "Connection unexpectedly closed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60864475/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com