0

I upload a Web app created by Django(with Apache2) to AWS. I can send Emails from a Form on Ubuntu, but I can not on AWS EC2 and Server Error(500) occurs even if I use the same codes.

If I send Email with python manage.py shell_plus, I can send Email.

[ec2-user@]$ python manage.py shell_plus
>>> from django.core.mail import send_mail
>>> send_mail(mail_subject, mail_message, mail_from, mail_to, fail_silently=False,)

But I cannot from the Django Web app.

What should I do to send Email as Gmail? Or should I use Amazon SES instead?

Thanks.

settings.py

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get("GMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.environ.get("GMAIL_HOST_PASSWORD")
EMAIL_FROM_EMAIL = os.environ.get("GMAIL_HOST_EMAIL")
EMAIL_USE_TLS = True

I added Inbound Rule(EC2)

port:587  IPv4:0.0.0.0

Django 4.1.7 Python 3.8.16 Apache 2.4.56 mod_wsgi 4.9.4

K-Yuuma
  • 31
  • 6
  • _But I cannot from the Django Web app_ What do you mean you "cannot"? What happens when you try? – John Gordon Mar 26 '23 at 14:43
  • Thank you for your reply. When I tried, just displayed Server Error(500) on Browser. I read `/etc/httpd/logs/error_log`, but nothing was written about the failure of sending Gmail. – K-Yuuma Mar 26 '23 at 15:18
  • 1
    You may be able to work around this issue by turning on [2FA in Gmail and enabling app passwords](https://stackoverflow.com/a/63043473). – Anon Coward Mar 26 '23 at 16:26
  • Thank you. I had already done the 2FA. After I read the page you linked and understood what I tried to do was difficult, I understood Google does not want people to do what I tried to do. – K-Yuuma Mar 29 '23 at 14:11

0 Answers0