Django send_mail not working

后端 未结 3 566
误落风尘
误落风尘 2020-12-30 06:41

When the view that sends the email is used nothing happens, i then entered send_mail(...) into the python shell and it returned 1 but i didn\'t receive any emails.

T

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 07:35

    Adjust your settings thus:

    DEFAULT_FROM_EMAIL = 'workorbit@gmail.com'
    SERVER_EMAIL = 'workorbit@gmail.com'
    EMAIL_USE_TLS = True
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 587
    EMAIL_HOST_USER = 'workorbit@gmail.com'
    EMAIL_HOST_PASSWORD = 'P@ssw0rd5'
    

    Adjust your code:

    from django.core.mail import EmailMessage
    
    def send_email(request):
        msg = EmailMessage('Request Callback',
                           'Here is the message.', to=['charl@byteorbit.com'])
        msg.send()
        return HttpResponseRedirect('/')
    

提交回复
热议问题