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?
Related
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 working on a Django application.
I have set up all my required password reset views and corresponding pages.
In the final step I want to use Send Grid in my application to send the emails. I have the following setting s in my base.py file
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = 'codesniper99' # email id
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_HOST_PASSWORD = '****' #password
EMAIL_USE_TLS = True
where **** is my password for the username codesniper99 on sendgrid.com
But when I use the password reset function I get locally generated email to my account. Like when i put email for reset as akhilvaid21#gmail.com
I get this:
when I push my code to my production server and not local host then it doesn't work and no email is sent. What am I doing wrong?
Also how do I change the name of webmaster#localhost???
Make sure you have set DEFAULT_FROM_EMAIL and SERVER_EMAIL in your settings.
Many email providers will only let you send email from verified email addresses. It looks as if Sendgrid might be blocking emails because Django is using the default webmaster#localhost for DEFAULT_FROM_EMAIL.
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>"
Django websites were working 100% with contact form that sends email via google apps. Recently it stopped working that I need to turn on this feature:
Allowing less secure apps to access your account
Link:
https://support.google.com/accounts/answer/6010255?hl=en
How to achieve to send emails via contact form using google apps but secured way. I do not want my google apps account to be less secure only because of this contact form. Is there a way to set an exception in google apps account for this website / IP or somehow? I would like to have it set proper way.
This setting worked previously till now when I had to turn on less secure apps feature on.
RECAPTCHA_PUBLIC_KEY = env("RECAPTCHA_PUBLIC_KEY", default='XXX')
RECAPTCHA_PRIVATE_KEY = env("XXX", default='RECAPTCHA_PRIVATE_KEY')
CONTACT_EMAIL_SUBJECT = 'CUSTOM SUBJECT'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'EMAIL ADDRESS'
EMAIL_HOST_PASSWORD = 'EMAIL PASSWORD'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'EMAIL ADDRESS'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'