gpt4 book ai didi

python - django 错误未发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 05:38:14 24 4
gpt4 key购买 nike

我正在尝试部署我的第一个 Django 应用程序。设置电子邮件日志记录,以便我可以调试任何服务器端问题。我认为,设置文件中包含通过电子邮件发送异常信息的所有正确信息,但我没有收到任何电子邮件。

我猜这个错误可能是在 django 实际发生之前发生的。哎呀,这个设置对吗?

设置文件:

DEBUG = False
TEMPLATE_DEBUG = DEBUG

EMAIL_HOST= 'smtp.gmail.com'
EMAIL_HOST_USER='user@gmail.com'
EMAIL_HOST_PASSWORD='password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

ADMINS = (
'me', 'myaddress@domain.com',
)

SERVER_EMAIL = 'user@gmail.com'

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database', # Or path to database file if using sqlite3.
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}

TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

SECRET_KEY = 'secret'

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = ''

#WSGI_APPLICATION = 'PFM.wsgi.application'

import os
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/'),)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'django.contrib.humanize',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'finances',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.openid',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
"django.contrib.auth.context_processors.auth",
)

AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)

SOCIALACCOUNT_PROVIDERS = \
{
'openid':
{ 'SERVERS':
[dict(id='yahoo',
name='Yahoo',
openid_url='http://me.yahoo.com'),
dict(id='hyves',
name='Hyves',
openid_url='http://hyves.nl'),
dict(id='google',
name='Google',
openid_url='https://www.google.com/accounts/o8/id')]

}
}

LOGIN_REDIRECT_URL = "/finances/transactions/"
ACCOUNT_LOGOUT_REDIRECT_URL = "/accounts/login"
ACCOUNT_USERNAME_REQUIRED = True

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

最佳答案

您可以尝试此设置

#  FOR YOUR E-MAILS
DEFAULT_FROM_EMAIL='webmaster@localhost' # or webmaster@servername
SERVER_EMAIL='root@localhost' # or 'root@servername'
EMAIL_HOST = 'localhost' # or servername
EMAIL_HOST_USER='' # or 'user@gmail.com'
EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend'
EMAIL_PORT = 25 #587
EMAIL_USE_TLS = True

关于python - django 错误未发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18335799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com