Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x &引用;“连接意外关闭”;从AWS使用SES发送电子邮件时出错_Python 3.x_Amazon Web Services_Smtplib - Fatal编程技术网

Python 3.x &引用;“连接意外关闭”;从AWS使用SES发送电子邮件时出错

Python 3.x &引用;“连接意外关闭”;从AWS使用SES发送电子邮件时出错,python-3.x,amazon-web-services,smtplib,Python 3.x,Amazon Web Services,Smtplib,所以我尝试用SMTP和AWS向我自己发送电子邮件。我在配置中使用的电子邮件经过验证,因为我仍然在SES中使用沙盒模式。在运行脚本时,我一直收到错误连接意外关闭即使我尝试连接OpenSSL,但它已连接,但在服务器响应中显示未找到STARTTLS,无论如何尝试…连接后出错 这是我的密码: MAIL = {} MAIL['USERNAME'] = 'AKIAXARHTFGFKCDAO7PD' MAIL['PASSWORD'] = 'BE0tXPq8wteiKZYtgD2TgtfFTGhgFGOhUp3

所以我尝试用SMTP和AWS向我自己发送电子邮件。我在配置中使用的电子邮件经过验证,因为我仍然在SES中使用沙盒模式。在运行脚本时,我一直收到错误
连接意外关闭
即使我尝试连接OpenSSL,但它已连接,但在服务器响应中显示
未找到STARTTLS,无论如何尝试…
连接后出错

这是我的密码:

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)
---
我的文档来源:

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

MAIL['PORT'] = 587

有什么解决方案吗?@PATAPOsha我前一段时间发布了这篇文章,但我认为问题在于凭据错误。对我来说,465端口与
server.starttls()
不兼容。587起作用