I am having this error: smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials ij28-20020a170902ab5c00b00163efcd50bdsm1197936plb.94 - gsmtp') when I try to send a gmail in my registration app
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'repository0612#gmail.com'
EMAIL_HOST_PASSWORD = '****************'
EMAIL_PORT = 587
I read in some other related forums that you just have to turn on the less secure apps in your google account settings but google already disabled that particular setting. I also tried turning off the 2-way authentication and my EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are as the same as my email and password. What else should I do to solve this problem?
This feature is no longer supported as of May 30th, 2022. See https://support.google.com/accounts/answer/6010255?hl=en&visit_id=637896899107643254-869975220&p=less-secure-apps&rd=1#zippy=%2Cuse-an-app-password
https://stackoverflow.com/a/27515833/19312416
So for new users we wont be able to use less secure app due to a new update, but there is nothing to worry.
In gmail after you allow 2 step authendication you will get a feature named app passsword you can use this.
Go to app password > provide name > copy password.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER =
EMAIL_HOST_PASSWORD = "paste that password"
this will work!
i believe your problem with code, try my function, it works with gmail, without additional settings
import smtplib
from email.mime.text import MIMEText
def email_sender(to_email, theme, message):
sender = "example#gmail.com"
password = "mypassword"
body = message
# make up message
msg = MIMEText(body)
msg['Subject'] = theme
msg['From'] = sender
msg['To'] = ", ".join(to_email)
#sending
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(sender, password)
send_it = session.sendmail(sender, to_email, msg.as_string())
session.quit()
Thanks for the help guys. It already works by using the generated app password in my google account instead of using my own created password in EMAIL_HOST_PASSWORD
Related
SMTPConnectError at /investor/signup
(421, b'service not available (connection refused, too many connections)')
This Error has been delaying for days now, i'm really stuck while sending email with django and i'm a beginner in django that why i do not have many idea on how to solve this issue please can anyone help?
Setting.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'xxxxxxxxxxxxxxxx#gmail.com'
EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxxxxxxxx'
EMAIL_USE_TLS = True
I don't know if you've found the solution to this bug but coincidentally, I encountered the same issue recently... Here is the solution that worked for me. My assumption is that you already know how to generate secret password from gmail smpt.
I tried this using the EmailMessage class and the send_mail function. Both worked perfectly.
I'll share portions of both my settings.py and views.py files.Hope it works for you too... cheers!
settings.py
# smtp configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'xxxxxxxxxx#gmail.com'
EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxxxx'
EMAIL_USE_TLS = True
views.py
# user activation
current_site = get_current_site(request)
email_subject = 'Please activate your account',
message = render_to_string('accounts/account_verification_email.html', {
'user': user,
'domain': current_site,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': default_token_generator.make_token(user)
})
from_email = settings.EMAIL_HOST_USER
recipient = [email]
send_email = EmailMessage( email_subject, message, from_email, recipient)
send_email.send(fail_silently=False)
Alternate method using send_mail function:
subject = 'This is a mail from IfeCog'
message = f'hi {firstname}, this mail is about your registration'
from_email = settings.EMAIL_HOST_USER
recipient_list = [email]
send_mail(subject, message, from_email, recipient_list, fail_silently=False)
Have you tried enabling 'Less secure app access' , go to your gmail host 'manage account' -> 'security', make sure you have 'Less secure app access' enabled.
To Fix this issue, the easiest way to is use to SendGrid as thier server doesn't throw all the regular error gmail Simple Mail Transfer Protocol Throws. To get started using SendGrid in django, this is the best tutorial Article 1 and Official SendGrid X Django Docs
I'm currently building a contact form for my website in Django.
The only problem is that the email is not being sent when the form is submitted.
This is the code:
settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = "c******o#gmail.com"
EMAIL_HOST_PASSWORD = '****'
EMAIL_PORT = '587'
views.py:
sender_name = form.cleaned_data['nome_completo']
sender_email = form.cleaned_data['email']
message = "{0} has sent you a new message:\n\n{1}".format(sender_name, form.cleaned_data['messaggio'])
send_mail('New Enquiry', message, sender_email, ['c******o#gmail.com'])
My thought:
Since I'm in a virtualenv, when I submit the form, the terminal displays that it was successfully submitted, and gets me back the code right, maybe the email is not sent because of that, or maybe because I'm using a gmail account? Thanks!
Since you are using an SMTP server, why not use the following backend:
django.core.mail.backends.smtp.EmailBackend
Also, if you are using Gmail, make sure of the following:
Two-Factor authentication is enabled on account
You are using an app password.
You can find these on the security tab on your google account page:
https://myaccount.google.com/security
So the issue is with EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
This outputs emails to your console for debugging instead of actually sending emails. (See https://docs.djangoproject.com/en/3.1/topics/email/#console-backend)
Don't set EMAIL_BACKEND to anything for production as it defaults to django.core.mail.backends.smtp.EmailBackend. Then your EMAIL_HOST settings will take effect and the email should be sent out.
I am using a business email for my website. Website has two parts, One is "Contact Us" form where email will be sent to my [business email]. Second part requires email to be sent from [business email] to customers emails.
I have set up django mail as per documentation:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'cp1.mywebsitebox.com'
EMAIL_HOST_USER = '*********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 26
DEFAULT_FROM_EMAIL = '*******'
Issue is that, first part goes well. Email recieves successfully at [business email] but second part is totally not working. Instead of being sent to recipient, it appears only in console.
Can anyone suggest what the issue is?
it may be issue from your mailing server, can you try gmail server for testing
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_HOST = ‘smtp.gmail.com’
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘your_account#gmail.com’
EMAIL_HOST_PASSWORD = ‘your account’s password’
and enable less secure app for testing
https://myaccount.google.com/lesssecureapps
I'm creating email system in my django project and faced to next question:
Send email from custom email sender name, f.e. sending email from gmail(btw it works in my project) requires sending messages only from gmail account, same thing with smtp-pulse, sendgrid and etc. .
My question is: May I use any of already configured smtp servers in my case, or I only need to create my own using smtplib(f.e) and configure it?
Tried:
DEFAULT_FROM_EMAIL = 'support#site.com'
SERVER_EMAIL = 'support#site.com'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 2525
EMAIL_USE_TLS = False
EMAIL_HOST_USER = 'user#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
This one doesn't work.
Same with mail.ru/smtp-pulse.com
Try
DEFAULT_FROM_EMAIL = "Site Support <support#site.com>"
I was trying to send a verification email at my program, when I use gmail it works and send the verification email but now im trying to use my own mail server and it started to raise this error
SMTPAuthenticationError at /accounts/register/
(535, '5.7.8 Error: authentication failed:')
any idea why?
# EMAIL SETTINGS
EMAIL_HOST = "smtp.xxxx.xxx"
EMAIL_PORT = "25"
EMAIL_HOST_USER = "no-reply#xxxxx.net"
EMAIL_HOST_PASSWORD = "xxxxxxxxxxxxxxxxxx"
# Controls whether a secure connection is used.
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
Verify the username and password are exactly the same,
Do not give full e-Mail id if in case your smtp accepts just the username without domain
e.g.
e-Mail id : username#abc.com
in settings file, just give username when your smtp accepts it.