[PYTHON] [Django] Settings for sending emails using postfix

postfix installation

stop sendmail

$ sudo service sendmail stop
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]

postfix installation

$ sudo yum install postfix

Check the version below

$ postconf  mail_version
mail_version = 2.6.6

This time 2.6.6 is included

MTA switching setting, automatic start setting

$ sudo alternatives --config mta

There are 2 programs'mta'To provide.

Select command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

Press Enter to select the current[+]Or enter the selection number

Enter 2 to switch to postfix

$ sudo chkconfig sendmail off
$ chkconfig --list sendmail
sendmail       	0:off	1:off	2:off	3:off	4:off	5:off	6:off
$ sudo chkconfig --add postfix
$ sudo chkconfig postfix on
$ chkconfig --list postfix
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

Disable sendmail autostart, enable postfix autostart

Email sending test

$ sendmail [email protected]
From:[email protected]
To:[email protected]
Subject:Test transmission
It is a test transmission
.

Check if an email has been sent to [email protected] If you get an error like postdrop: warning: unable to look up public / pickup: No such file or directory, take action below.

$ sudo service postfix restart
Shutting down postfix:                                     [FAILED]
Starting postfix:                                          [  OK  ]

## Django settings Add the following in setting.py

setting.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 = 'Sender name<[email protected]>'
....

## Editing /etc/postfix/main.cf ``` $ sudo vi /etc/postfix/main.cf ```

Add the following

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

The part of example.com describes the domain name of the outgoing email address

reference

Install Postfix and send an email | Today as well python - How do you configure Django to send mail through Postfix? - Stack Overflow

Recommended Posts

[Django] Settings for sending emails using postfix
DEBUG settings when using Django
WEB application development using Django [Initial settings]
DB settings when using Django + SQLAlchemy + Alembic
Django 1.9 for internationalization
django default settings
Django + MySQL settings
Django URL settings
Initial settings for using Python3.8 and pip on CentOS8
Spacemacs settings (for beginners)
Try using Django templates.html
Django command completion settings
Proxy settings for urllib.request