• django发送邮件时报错 SMTPSenderRefused (501, b'Mail from address must be same as authorization user.', 'webmaster@localhost') ,Connection unexpectedly closed


    原因没有开启 TLS

    应设置 EMAIL_USE_TLS = True       #    QQ邮箱必须开启

    开启后又报错:Connection unexpectedly closed

    原因:端口号可能有问题,换端口号

    EMAIL_PORT = 25       成功

     完整设置如下:

    settings.py

    STATIC_URL = '/static/'
    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = 'smtp.qq.com' # 如果是 163 改成 smtp.163.com
    EMAIL_PORT = 25 # 或者 995是设置了 SSL 加密方式
    EMAIL_HOST_USER = '321459055@qq.com' # 发送者账号
    EMAIL_HOST_PASSWORD = 'nweghpbjusqtbhie' # 授权码(****
    EMAIL_USE_TLS = True # QQ邮箱为True
    DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

    views.py

    def send_email(request):
    from_email = settings.DEFAULT_FROM_EMAIL
    send_mail('MyDjango test2', 'This is Django', from_email, ['1848872115@qq.com', ])
    return HttpResponse('send success!')



    urls.py

      urlpatterns = [
        path('admin/', admin.site.urls),
        path('send/',send_email),
      ]

  • 相关阅读:
    RadAsm使用
    如何从外网访问内网
    装SQL server 2008问题解决
    820
    大三学生经验之谈
    ROM与RAM知识
    java mybatis学习一
    java Sprint boot 学习之一
    java读取配置到Hash表里
    数组乱序算法
  • 原文地址:https://www.cnblogs.com/xiaohaodeboke/p/12433995.html
Copyright © 2020-2023  润新知