setting.py
1 # 邮件配置 2 EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend‘ 3 EMAIL_HOST = ‘smtp.exmail.qq.com‘ # 发送邮件的服务器地址 4 EMAIL_HOST_USER = ‘[email protected]‘ # 不含‘@126.com’的后缀 5 EMAIL_HOST_PASSWORD = ‘‘ # 非邮箱登录密码 6 EMAIL_PORT = 25 7 EMAIL_USE_TLS = True 8 EMAIL_FROM = ‘[email protected]‘ # 设置默认的发件人,不设置的话,本例中不会出现问题,但是在实际django中实际运用时,会出现问题,参见 http://blog.chinaunix.net/uid-21142030-id-5768057.html
view.py
1 from django.core.mail import send_mail 2 from dj_01 import settings 3 4 def send(request): 5 msg = ‘服务器运行良好‘ 6 send_mail( 7 subject=‘请注意这是Django邮件测试‘, 8 message=msg, 9 from_email=settings.EMAIL_HOST_USER, 10 recipient_list=["[email protected]","[email protected]"], # 这里注意替换成自己的目的邮箱,不然就发到我的邮箱来了:) 11 fail_silently = False, 12 ) 13 return HttpResponse(‘测试邮件已发出请注意查收‘)
原文地址:https://www.cnblogs.com/zhang-dan/p/11988370.html
时间: 2024-11-09 06:25:58