0

我试图在 AWS 上设置一个 Weblate 实例来发送密码重置电子邮件。我按照以下步骤操作:

pip install boto
pip install django-ses
sudo vim /opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.1.4-py3.7.egg/django/conf/global_settings.py
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = 'xxxx'
AWS_SECRET_ACCESS_KEY = 'xxx'

但是它仍然无法正常工作,并且我没有收到任何错误。我的 AWS 密钥拥有 SES 的完全权限。

更新:

如果我运行 send_mail 从./manage.py shell我得到这个输出:

>>> send_mail('Subject here', 'Here is the message.', 'xx@gmail.com',['xx@gmail.com'], fail_silently=False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/bitnami/apps/weblate/venv/lib/python3.7/site-packages/django/core/mail/__init__.py", line 60, in send_mail
    return mail.send()
  File "/opt/bitnami/apps/weblate/venv/lib/python3.7/site-packages/django/core/mail/message.py", line 291, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/opt/bitnami/apps/weblate/venv/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 103, in send_messages
    new_conn_created = self.open()
  File "/opt/bitnami/apps/weblate/venv/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 63, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/opt/bitnami/python/lib/python3.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/opt/bitnami/python/lib/python3.7/smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/opt/bitnami/python/lib/python3.7/smtplib.py", line 307, in _get_socket
    self.source_address)
  File "/opt/bitnami/python/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/opt/bitnami/python/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
4

1 回答 1

0

您正在编辑 Django 默认设置,这是更改配置的奇怪方式,但似乎 Bitnami 推荐这种方法。似乎该设置未正确应用,因为测试命令仍使用默认 SMTP 后端。

检查事项:

  • 实际应用的是设置:./manage.py shell -c 'from django.conf import settings; print(settings.EMAIL_BACKEND)'
  • django-ses安装到系统中了吗?最好以root身份运行安装sudo pip install django-ses
  • 你不是在混合 Python 2 和 Python 3 环境吗(不确定在 Bitnami 图像中是如何完成的)
于 2019-05-16T08:53:47.383 回答