How do you configure Django and Postfix to send emails for Django apps?
如何配置Django和Postfix为Django应用程序发送电子邮件?
I am able to do it using Gmail server settings but I want to send email from my own server using my own domain.
我能够使用Gmail服务器设置,但我想使用自己的域从我自己的服务器发送电子邮件。
1 个解决方案
#1
21
I banged my head a lot before realizing that it is actually quite simple:
在意识到它实际上非常简单之前,我猛烈抨击了我的脑袋:
add this to your settings.py
将其添加到您的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 <whatever@example.com>'
Also make sure that a fully qualified domain name (say mybox.example.com) is set up on your server (how),
还要确保在您的服务器上设置了完全限定的域名(例如mybox.example.com)(如何),
Then you need to have these lines in your /etc/postfix/main.cf:
然后你需要在/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)
此外,您必须在您的DNS服务器(在您的注册商中,如果您通过它们处理dns查找)为您的域设置正确的MX记录(请在此处查看)
#1
21
I banged my head a lot before realizing that it is actually quite simple:
在意识到它实际上非常简单之前,我猛烈抨击了我的脑袋:
add this to your settings.py
将其添加到您的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 <whatever@example.com>'
Also make sure that a fully qualified domain name (say mybox.example.com) is set up on your server (how),
还要确保在您的服务器上设置了完全限定的域名(例如mybox.example.com)(如何),
Then you need to have these lines in your /etc/postfix/main.cf:
然后你需要在/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)
此外,您必须在您的DNS服务器(在您的注册商中,如果您通过它们处理dns查找)为您的域设置正确的MX记录(请在此处查看)