【发布时间】:2017-08-29 13:10:16
【问题描述】:
我有一个在本地主机上正常工作的 smpt 邮件,但是当我将应用程序放在服务器上时,它不发送邮件。我认为有一些配置问题。 我正在使用 apace2 ubuntu server 14.04,并且我已将我的项目放在 /var/www/ 文件夹中。我通过配置 000-default.conf 文件来强制 https 连接
设置.py
TEMPLATE_DEBUG =False
SECRET_KEY = **key**
DEBUG = False
ALLOWED_HOSTS = [**allowed hosts**]
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = (
'index',
'aboutus',
'aboutus.team',
'aboutus.careers',
'aboutus.locations',
'aboutus.board',
'domainsec',
'projects',
'downloads',
'contactus',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
X_FRAME_OPTIONS = 'DENY'
ROOT_URLCONF = **urls**
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'antef.wsgi.application'
# Email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = **emailid**
EMAIL_HOST_PASSWORD = **password**
EMAIL_PORT = 587
EMAIL_USE_TLS = True
apache_config 文件:
<VirtualHost *:443>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteEngine on
SetEnvIfNoCase User-Agent ^libwww-perl bad_bot
BrowserMatchNoCase SpammerRobot bad_bot
BrowserMatchNoCase SecurityHoleRobot bad_bot
<Location />
Order allow,deny
Allow from all
Deny from env=bad_bot
</Location>
<IfModule mod_headers.c>
Header set Set-Cookie HttpOnly;Secure
</IfModule>
</VirtualHost>
//apache2.conf
【问题讨论】:
-
尝试设置
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'并查看控制台日志。 -
如果您在 Stack Overflow 上搜索“gmail django”,您会发现许多用户在尝试配置它时遇到问题。有一些步骤,例如打开可能对您有用的不太安全的应用程序的访问权限。但是,您可能会发现使用不同的邮件提供商会更容易。
-
我已打开安全性较低的应用程序的访问权限。它从本地主机发送电子邮件但在服务器上不起作用
-
当我尝试从浏览器访问时,它显示“发生服务器错误。请联系管理员。”
-
在我的终端上:“ImportError: No module named security”