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?