Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django send_mail with SMTP backend cannot send out email

Tags:

email

django

smtp

I am deploying a Django project on an ubuntu stack with a postfix SMTP mail server, hosted on Amazon's EC2. I can send out email from the server using the Linux mail program. But when I try to send email using django.core.mail.send_mail, the email is never received.

Here are my settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

I left everything else as default.

I tried

python manage.py shell

Then in the shell, I did

from django.core.mail import *
send_mail(
    'TEST',
    'THIS IS A TEST',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
    )

This returns 1, but I never received any message at the destination ('[email protected]' in the example).

Is there a tutorial on how to configure a SMTP server to work with Django's mail system? Thanks.

like image 402
user560494 Avatar asked Jul 11 '11 03:07

user560494


1 Answers

I assume that you did specify your EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD in your settings.py right?

A detailed explanation of how the default django.core.mail.backends.smtp.EmailBackend works is explained - https://docs.djangoproject.com/en/dev/topics/email/ https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend

And specifically for your email port, you did open your port for smtp under EC2's security group? SMTP port usually defaults to 25 if you left it as default during your postfix configuration and it is important that you have opened up that port when you created your EC2 instance.

like image 177
Calvin Cheng Avatar answered Oct 15 '22 00:10

Calvin Cheng