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
Related
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
I set up an email account with NameCheap that I use with my Django app. Below is my email configuration based on information provided by NameCheap
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'news#mydomain.com'
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD')
EMAIL_USE_SSL = True
DEFAULT_FROM_EMAIL = 'WebsiteTitle <news#mydomain.com>'
Now when I use send_mail() django function (eg. after registration) it is like playing roulette - one time it works properly and sends out an email, another time it throws an error saying
SMTPServerDisconnected at /reset-password/
Connection unexpectedly closed
As if something was wrong with my email configuration.
Do you have any idea what might cause it or how to try to fix it or debug it? Is it more likely NameCheap or Django?
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 previously i was using gmail smtp to send mail**(working fine)** but now i created new account in sendgrid and im using free plan in my django project this my complete setting about send grid
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
EMAIL_HOST_PASSWORD = 'SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # this is API key
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
is any other settings required?? i am testing email using rest auth lib http://127.0.0.1:8000/rest-auth/password/reset/
is show msg like success": "Password reset e-mail has been sent."
but recipient did not received any mails but in sendgrid dashboard it is showing 9 or 10 etc msg delivered
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>"