詹戈。使用应用程序发送电子邮件

2024-06-16 11:27:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我启动了一个新的应用程序gmail并在中配置了设置设置.py用我的gmail帐户

我刚到django,不知道如何给我的网站用户发送电子邮件

我想创建一个链接,当我打开它,我的用户将得到一个消息从我

我编辑过视图.py但我不知道我的函数“wyslij”应该返回什么

from django.shortcuts import render
from django.core.mail import send_mail
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth.models import User
from userprofile.models import UserProfile


@user_passes_test(lambda u: u.is_superuser)
# Create your views here.
def wyslij(request):
    # Create the HttpResponse object with the appropriate PDF headers.


    uzyt = UserProfile.objects.all().order_by('user_id')



    for z, uzyt in enumerate(UserProfile.objects.all()):

        send_mail('The exam is comming', 'Hi, Your exam will be tomorrow!', 'santa.claus.for.grace@gmail.com', [uzyt.email], fail_silently=False)


    return response 

在网址.py你知道吗

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns('',
    url(r'^accounts/wyslij/$', 'gmail.views.wyslij'),
)

Tags: django用户frompyimportauthsendmail
2条回答

https://docs.djangoproject.com/en/1.7/topics/email/

一定要命名你的电子邮件变量和.git忽略你的设置文件

在设置.py,您必须添加这些内衬:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'xxxxxxxxxxx@gmail.com'
EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxx'
EMAIL_PORT = 587    #or try with 25

相关问题 更多 >