django发邮件
- 配置setting信息
-
1 EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend‘ 2 3 4 EMAIL_HOST = ‘smtp.qq.com‘ 5 EMAIL_PORT = 25 6 EMAIL_HOST_USER = your email address 7 EMAIL_HOST_PASSWORD = ‘our email key 8 EMAIL_FROM = ‘<your email address>‘
- 我这里用的qq提供的smtp,EMAIL_HOST 设置为: ‘smtp.qq.com‘
- EMAIL_PORT默认为25
- EMAIL_HOST_USER为你的邮箱地址
- EMAIL_HOST_PASSWORD设置:
- 打开你的qq邮箱→设置→账户→POP3/SMTP服务→开启
- 发送短信,获取密码
- EMAIL_FROM:一个字符串,尖括号里面包裹的是你的email
-
- 发送邮件
-
1 def sendEmail(request): 2 email = request.POST.get(‘email‘) # 获取post请求里面的email地址 3 subject = "" # 邮件的标题 4 message = "" # 邮件的正文 5 sender = settings.EMAIL_FROM # 邮件的发送者 6 receiver = [email] # 邮件的接受者(列表形式) 7 send_mail(subject, message, sender, receiver) 8 return HttpResponse(‘发送成功!‘)
-
原文地址:https://www.cnblogs.com/ivy-blogs/p/10961494.html
时间: 2024-11-09 02:42:48