1.qq邮箱设置中,开启pop3/smtp服务
2.生成授权码(先复制下来)
3.django配置
# 以下是邮箱配置项
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.qq.com' # 腾讯qq邮箱,smtp服务器地址
EMAIL_PORT = 25 #smtp服务端口,465/587(这个两个腾讯官方给的端口号,我用不了)
EMAIL_HOST_USER = 'xxxxxxxxxx@qq.com' # 发送邮件的邮箱
EMAIL_HOST_PASSWORD = 'xxxxxxxxx' # 在邮箱中设置的客户端授权密码
EMAIL_FROM = 'xxxxxxxxx@qq.com' # 收件⼈看到的发件⼈
EMAIL_USE_TLS = False # 与smtp服务器通信时,是否启动TLS链接(安全链接)默认False
4.创建函数,发送短信
from django.core.mail import send_mail
from django.conf import settings
def send_verify_email(to_email, verify_url):
"""
:param to_email: 收件人邮箱
:param verify_url: 邮箱激活url
"""
subject = "xx邮箱验证" # 主题/标题
html_message = '<p>尊敬的⽤户您好!</p>' \
'<p>您的邮箱为:%s 。请点击此链接激活您的邮箱:</p>' \
'<p><a href="%s">%s<a></p>' % (to_email, verify_url, verify_url)
send_mail(subject, '', settings.EMAIL_FROM, [to_email, ], html_message=html_message) # 注意赋值顺序
"""
def send_mail(
subject, # 标题
message, # 普通邮件正文
from_email, # 发件人
recipient_list, # [收件人]
fail_silently=False,
auth_user=None,
auth_password=None,
connection=None,
html_message=None, # 超文本的邮件内容
)
"""
标签:qq,smtp,EMAIL,邮箱,django,email From: https://www.cnblogs.com/yeli-oneselfblogs/p/17210250.html