I've tried sending emails with my Gmail account in Django, but I always get errors. I tried using a sandbox (Mailtrap) and it worked but using the actual Gmail account doesn't. I've also tried using App Password in my google account but it still doesn't work.
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "password"
Error I always get;
SMTPConnectError at /send/
(421, b'Service not available')
Please how can this be fixed.
CodePudding user response:
You have serval options.
Apps password smtp
Does the google account you are using have 2fa enabled, if it does then you can create an apps password. Then take the apps password and use that implace of the password in your code.
XOauth2 smtp
Depending upon the system you are using to send emails it may support Xoauth2 authorization. If it does then you can use that to send emails via the smtp server.
Gmail api. Oauth2 or service accounts
You can switch to using the gmail api, if you have a workspace account then you could use service accounts. If not then you will need to stick with Oauth2 and authorize your appliaton once. This is simarl to using Xoauth2 with the smtp server only you will be going though the gmail api instead.
CodePudding user response:
Google doesn't allow this anymore. You can check sendgrid or other alternatives.