zoukankan      html  css  js  c++  java
  • django 中发送邮件

    1、首先开启smtp

    django 内部自己有一套邮件系统只需要配置如下内容即可

    settings文件,(固定格式不用记)

    # 邮件配置
    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    # EMAIL_USE_TLS = False   #是否使用TLS安全传输协议(用于在两个通信应用程序之间提供保密性和数据完整性。)
    # EMAIL_USE_SSL = True    #是否使用SSL加密,qq企业邮箱要求使用
    EMAIL_HOST = 'smtp.163.com'   #发送邮件的邮箱 的 SMTP服务器,这里用了163邮箱
    EMAIL_PORT = 25     #发件箱的SMTP服务器端口
    EMAIL_HOST_USER = 'xxxxxxxxxxxxxxxxxxxx'    #发送邮件的邮箱地址
    EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxxxx'         #发送邮件的邮箱密码(这里使用的是授权码)

    需要发送邮件时定义邮件,调用send_mail即可

    from django.conf import settings
    from django.core.mail import send_mail
    
    
    def send_register_email(to_email, username, content):
        # 标题
        subject = ''
        # 内容
        message = content
        # 支持html格式
        html_message = '#')
        # 用哪个邮箱发
        sender = settings.EMAIL_HOST_USER
        # 发送给谁
        receiver = [to_email]
        send_mail(subject, message, sender, receiver, html_message=html_message)
  • 相关阅读:
    php多态
    ssl certificate problem: self signed certificate in certificate chain
    test plugin
    open specific port on ubuntu
    junit vs testng
    jersey rest service
    toast master
    use curl to test java webservice
    update folder access
    elk
  • 原文地址:https://www.cnblogs.com/HByang/p/13581062.html
Copyright © 2011-2022 走看看