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