【发布时间】:2020-03-25 00:21:23
【问题描述】:
我有一个位于 AWS EC2 中的 Django 应用程序,我想连接到 AWS SES 以发送电子邮件,所以我遵循了这个教程: https://kholinlabs.com/the-easiest-way-to-send-emails-with-django
首先,我在ap-southeast-1a可用区创建了一个EC2实例,入站和出站规则如下:
入站规则:
HTTP TCP 80 0.0.0.0/0
All traffic All All 0.0.0.0/0
All traffic All All ::/0
SSH TCP 22 0.0.0.0/0
SMTPS TCP 465 0.0.0.0/0
SMTPS TCP 465 ::/0
HTTPS TCP 443 0.0.0.0/0
出站规则:
All traffic All All 0.0.0.0/0
All traffic All All ::/0
然后我在服务器内部创建了 Django 应用程序:
django-admin startproject mysite
python3 manage.py makemigrations
python3 manage.py migrate
在设置文件中添加以下行:
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = 'secret'
AWS_SECRET_ACCESS_KEY = 'secret'
AWS_SES_REGION_NAME = 'ap-southeast-2'
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-southeast-2.amazonaws.com'
然后我在 ap-southeast-2 avalibility zone 中创建了一个 SES 实例。
在 EC2 服务器中,我按照教程输入命令:
python3 manage.py shell
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from@example.com',
['to@example.com']
)
但它卡了很长时间(大约 10 分钟),然后显示超时消息。
有没有我遗漏的步骤?
其他信息: 远程登录:
telnet email-smtp.ap-southeast-2.amazonaws.com 465
Trying 3.24.207.252...
Connected to email-smtp.ap-southeast-2.amazonaws.com.
Escape character is '^]'.
465端口可以工作
telnet email-smtp.ap-southeast-2.amazonaws.com 25
Trying 13.238.20.185...
它卡在 25 端口
telnet email-smtp.ap-southeast-2.amazonaws.com 587
Trying 3.24.207.252...
Connected to email-smtp.ap-southeast-2.amazonaws.com.
Escape character is '^]'.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-EHZHT2N2F i9ibRsZcZvQJA54s7GtJ
451 4.4.2 Timeout waiting for data from client.
Connection closed by foreign host.
【问题讨论】:
标签: django amazon-ec2 amazon-ses