I can send “reset password” mail but cannot use the “send_mail”

I want to send a “greetings” mail, when people sign up for my webpage.

I can send a “reset password” email using the built in auth_views.PasswordResetView but when I try use the django.core.mail.send_mail I get an Username and Password not accepted.

My settings.py

.
.
#Email config
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 
EMAIL_USE_TLS = True
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = "My Name <no-reply@my_site.com>"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = app_cred
EMAIL_HOST_USER = app_email

and views.py

def register(request):
    if request.method=="POST": #post request
        form = UserRegisterForm(request.POST)
        agree_form = AgreeForm(request.POST)
        if form.is_valid() and agree_form.is_valid():
            user = form.save(commit=False)
            user.email = form.cleaned_data["email"]
            user.save()
            
            send_mail(subject = "Welcome to my-site.com",
            message = "Welcome!",
            from_email = None,
            recipient_list = [user.email])
            return redirect("login")
    else:
        form = UserRegisterForm()
        agree_form = AgreeForm()

    return render(request,"users/register.html",context= {"form":form,"agree_form":agree_form})

As far as I understand, Django uses the credentials specified in the settings, so I wonder why I can send a password-reset mail but cannot use the send_mail method using the same credentials?

Hello, did you check your Gmail account if there is any alert from Google regarding sending emails?

No alerts/emails at all

This is funny coincidence. I just found out that my “greetings” email for new project works, but those for resetting password don’t :frowning:

I’ll let you know once I fix this where the problem was

So, found it :smiley: I am using email as a username but the reset password feature uses the email field on the user. So I needed to populate the email field as well.

My error is regarding the from_email and not the to_email, unfortunately (I’m using email as username aswell)

If the from_email isn’t the same name as the credentials being used, is that name “registered” with gmail as being authorized to be sent from that account? (gmail doesn’t allow the use of arbitrary from addresses)

What happend was, that I had recently changed my password, and for some reason, that removed my app-passwords in gmail i.e the credentials was purely wrong