0

I need Django to send a confirmation email, but it keeps telling me my email is not a valid address - is there something wrong with my code?

Error:

SMTPRecipientsRefused at /accounts/signup

{'=?utf-8?q?email?=': (553, b'5.1.2 The recipient address <=?utf-8?q?email?=> is not a valid RFC-5321\n5.1.2 address. h7-v6sm4740542wmc.44 - gsmtp')}

Views.py function:

def signup(request):
    if request.method == 'POST':
        if request.POST['password1'] == request.POST['password2']:
            try:
                user = User.objects.get(username=request.POST['username'])
                return render(request, 'accounts/signup.html', {'error':'Username has already been taken'})
            except User.DoesNotExist:
                user = User.objects.create_user(request.POST['username'], password=request.POST['password1'], email=request.POST['email'])
                email = user.email
                auth.login(request, user)
                msg = EmailMessage('Request Callback',
                       'Here is the message.', to=['email'])
                msg.send()
                return redirect('home')
        else:  #<---- I think you need this one too
            return render(request, 'accounts/signup.html', {'error':"Passwords didn't match"})
    else:
        #if it's a GET
        return render(request, 'accounts/signup.html')
Davtho1983
  • 3,827
  • 8
  • 54
  • 105

1 Answers1

1

If this is your actual code, You're sending the email to "email", not the value of the email variable you define earlier.

So,

msg = EmailMessage('Request Callback','Here is the message.', to=[email, ])
SpiXel
  • 4,338
  • 1
  • 29
  • 45