尝试使用Django

时间:2018-06-27 11:47:41

标签: django django-settings django-email django-errors

我正在尝试构建一个模块,以允许我向用户发送电子邮件。 但是,我遇到了一个错误:

/ email中的

TimeoutError [Errno 60]操作超时

urls.py

from django.contrib import admin
from django.conf.urls import url
from emailfunction.views import send_email

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^email', send_email),
]

views.py

from django.http import HttpResponse
from django.conf import settings
from django.core.mail import send_mail


def send_email(request):
    subject = 'Test Subject'
    message = 'Test Message./n 123 123 456 456 778 990./n From ABC/n'
    from_email = settings.EMAIL_HOST_USER
    to_list = ['receiver@gmail.com', settings.EMAIL_HOST_USER]
    send_mail(subject, message, from_email, to_list, fail_silently=False)
    return HttpResponse("Mail has been sent. Please check your mail. Thank YOU!")

settings.py中的相关详细信息

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'sender@gmail.com'
EMAIL_HOST_PASSWORD = '**************'
EMAIL_PORT = 587

0 个答案:

没有答案