I would like to send email from a django view. I got it to work on my local machine with django development server with the following settings:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
My view has
from django.core.mail import send_mail
def my_view(request):
send_mail('subject','body','user@gmail.com',['recipient@gmail.com'],fail_silently=False)
return render(request, 'index.html')
When I run send_mail() from manage.py shell on my production server, the email is successfully sent. However, when the view is invoked in production (nginx + uwsgi + django), no email is sent, even though the view runs without error and returns the expected response. I see no error in error.log.
Please help me set correct permissions and configurations for nginx so that this works.
NOTE: This question is similar to Send_mail in Django, works in shell, works locally, not in view, which was never resolved.
EDIT: When I do
sudo -u www-data python manage.py shell
to run as the nginx user, i can still successfully send mail, which confuses me even more.