Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you configure Django to send mail through Postfix? [closed]

How do you configure Django and Postfix to send emails for Django apps?

I am able to do it using Gmail server settings but I want to send email from my own server using my own domain.

like image 709
toothie Avatar asked Oct 13 '14 04:10

toothie


People also ask

How do I send an email using django?

In most cases, you can send email using django. core. mail. send_mail() .

How do I send and receive emails in django?

Use the get_new_mail method to collect new messages from the server. Go to Django Admin, then to 'Mailboxes' page, check all the mailboxes you need to receive emails from. At the top of the list with mailboxes, choose the action selector 'Get new mail' and click 'Go'.

How do you configure SMTP postfix mail in Linux?

Configuring PostfixAll of the options you need for the service are located in /etc/postfix . The main configuration file for the Postfix service is located at /etc/postfix/main.cf . Within the configuration file, there are many options that you can add, some of them more common than others.


1 Answers

I banged my head a lot before realizing that it is actually quite simple:

add this to your settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'Whatever <[email protected]>'

Also make sure that a fully qualified domain name (say mybox.example.com) is set up on your server (how),

Then you need to have these lines in your /etc/postfix/main.cf:

myhostname = mybox.example.com
mydestination = localhost.server.com, localhost, example.com

Also you have to set up proper MX record for your domain (check here) in your dns server (and in your registrar, if you handle dns lookup through you them)

like image 80
qliq Avatar answered Oct 16 '22 11:10

qliq