验证电子邮件未在ubuntu中使用本地服务器中的smtp发送到电子邮件地址

时间:2014-02-03 06:27:48

标签: python django email ubuntu

对于我的django project.i创建了一个注册表单,通常会要求用户提供他的电子邮件地址以进行变更。现在问题是当我以用户身份测试注册表单并传递我的电子邮件地址时,它显示了varificatio已发送到我的电子邮件地址,但没有电子邮件我找到了我的电子邮件收件箱。

现在问题是我如何使用本地服务器而不是活动服务器向我的电子邮件地址发送电子邮件在Ubuntu中。提到我使用的是smtp,我已将以下内容放入我的settings.py文件中..

EMAIL_FROM = 'raihncse43@gmail.com'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025

这是我的完整settings.py文件..

import sys
from os.path import abspath, dirname, join


sys.path.insert(0, '../..')

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ROOT_PATH = abspath(dirname(__file__))

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)


EMAIL_FROM = 'raihncse43@gmail.com'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025

MANAGERS = ADMINS

DATABASES = {
 'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': 'test.db'
}
}

TIME_ZONE = 'America/Montevideo'
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 = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

SECRET_KEY = '#$5btppqih8=%ae^#&7en#kyi!vh%he9rg=ed#hm6fnw9^=umc'

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 = 'example.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'example.wsgi.application'

TEMPLATE_DIRS = (
join(ROOT_PATH, 'templates'),
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'social.apps.django_app.default',
'example.app',
)

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,
    },
}
}

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
)

AUTHENTICATION_BACKENDS = (
'social.backends.amazon.AmazonOAuth2',
'social.backends.angel.AngelOAuth2',
'social.backends.aol.AOLOpenId',
'social.backends.appsfuel.AppsfuelOAuth2',
'social.backends.behance.BehanceOAuth2',
'social.backends.belgiumeid.BelgiumEIDOpenId',
'social.backends.bitbucket.BitbucketOAuth',

)

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/done/'
URL_PATH = ''
SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'
SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'
SOCIAL_AUTH_GOOGLE_OAUTH_SCOPE = [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/userinfo.profile'
]
# SOCIAL_AUTH_EMAIL_FORM_URL = '/signup-email'
SOCIAL_AUTH_EMAIL_FORM_HTML = 'email_signup.html'
SOCIAL_AUTH_EMAIL_VALIDATION_FUNCTION = 'example.app.mail.send_validation'
SOCIAL_AUTH_EMAIL_VALIDATION_URL = '/email-sent/'
# SOCIAL_AUTH_USERNAME_FORM_URL = '/signup-username'
SOCIAL_AUTH_USERNAME_FORM_HTML = 'username_signup.html'

#For Facebool Login using Social Auth
SOCIAL_AUTH_FACEBOOK_KEY='149560535145169'
SOCIAL_AUTH_FACEBOOK_SECRET='8db9dc18b04804895af8cf7a18fe5a4b'
SOCIAL_AUTH_FACEBOOK_APP_NAMESPACE = 'kothaymtl'
#SOCIAL_AUTH_FACEBOOK_EXTENDED_PERMISSIONS = ['email']


SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'example.app.pipeline.require_email',
'social.pipeline.mail.mail_validation',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
)

try:
from example.local_settings import *
except ImportError:
pass

现在就足以做到这一点或者我在这里缺少什么......

2 个答案:

答案 0 :(得分:1)

如果您使用Gmail帐户发送邮件,则必须使用smtp.gmail.com作为端口465和加密'ssl'的主机

答案 1 :(得分:0)

您需要在本地计算机上设置smtp服务器。 Postfix一个很棒的smtp电子邮件软件。

最简单的方法是设置postfix以使用您的Gmail帐户发送电子邮件。这是一个相同的好教程的链接: https://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/

配置Postfix后,您可以设置EMAIL_PORT=25或将其保留为默认值,然后您就可以发送电子邮件了。