I am trying to send the email from django web app. I used following
from django.core.mail import send_mail
send_mail('test email', 'hello world', 'your#email.com', ['aman.kumar#thoughts2binary.com'])
my setting is
DEFAULT_FROM_EMAIL = 'support#indianangelnetwork.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'support#indianangelnetwork.com'
EMAIL_HOST_PASSWORD = 'XXXXXXXXXX'
i am always getiing the mail from "support#indianangelnetwork.com". Although i am passing the send_from value.
This might be because you did not specify the password for your#email.com.
As a result Django falls back to the default settings.
See documentaion
Related
I have migrated an old codebase to a new server and am now running Django 4.0.5.
I can send emails from the shell as follows:
from django.core.mail import mail_admins
mail_admins(subject='test', message='test')
But I don't receive any emails on 500 or higher errors.
My settings are:
DEBUG = env('DEBUG')
ADMINS = [('My Name', 'me#provider.com'),]
MANAGERS = ADMINS
ADMIN_EMAIL = ['me#provider.com',]
DEFAULT_FROM_EMAIL = 'admin#provider.com'
SERVER_EMAIL = 'admin#provider.com'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'admin#provider.com'
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = True
And i have tried adding:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
But they are still not sent.
I am using django-environ, but debug is set to false.
Any ideas what the problem could be?
Have you checked this?
may be the problem is this.
https://support.google.com/accounts/answer/6010255?hl=en#:~:text=To%20help%20keep,continue%20to%20read.
I posted a question earlier where I asked how to get my email to send and was told that it's the provider, so I tried 3 providers and the send_mail and/or EmailMessage function doesn't work with any of them.
So, I strongly think it's something related to my set-up. I get a message in the send_email folder, but no email ever sends and no error is logged.
Here is my settings.py file:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myemails#gmail.com'
EMAIL_HOST_PASSWORD = 'pass'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = 'myemail#gmail.com'
Might someone else have an idea?
I have been trying everything to get django to send a test email, with no success. My test email is being sent from a python anywhere dev site. Here is my views ajax:
def ajaxLearning(request):
if request.method == 'GET':
from django.core.mail import send_mail
send_mail('Put your Email subject here', 'Put your Email message here.',
'myspamgoes#gmail.com', ['someemail#yahoo.com'],
fail_silently=False)
return HttpResponse("end");
else:
pass
And here is my settings.py:
DEFAULT_FROM_EMAIL = 'myspamgoes#gmail.com'
SERVER_EMAIL = 'myspamgoes#gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myspamgoes#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
At this point I feel as if I am making some higher level mistake such as, using the wrong version of django, failing to install something crucial, or doing something wrong on the gmail side. For the password, which I changed earlier today, I am using the one that I would use to normally sign in to my account. Thank you for taking the time to read my question!
Change in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=587
EMAIL_HOST_USER = 'myemailhere#gmail.com'
EMAIL_HOST_PASSWORD = '**********'
DEFAULT_FROM_EMAIL = 'myemailhere#gmail.com'
EMAIL_USE_TLS = True
When the view that sends the email is used nothing happens, i then entered send_mail(...) into the python shell and it returned 1 but i didn't receive any emails.
This is my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'senderaddress#gmail.com'
EMAIL_HOST_PASSWORD = 'Password1234!'
EMAIL_USE_TLS = True
This is the view:
def send_email(request):
send_mail('Request Callback', 'Here is the message.', 'senderaddress#gmail.com',
['recipientaddress#gmail.com'], fail_silently=False)
return HttpResponseRedirect('/')
Adjust your settings thus:
DEFAULT_FROM_EMAIL = 'workorbit#gmail.com'
SERVER_EMAIL = 'workorbit#gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'workorbit#gmail.com'
EMAIL_HOST_PASSWORD = 'P#ssw0rd5'
Adjust your code:
from django.core.mail import EmailMessage
def send_email(request):
msg = EmailMessage('Request Callback',
'Here is the message.', to=['charl#byteorbit.com'])
msg.send()
return HttpResponseRedirect('/')
Google now provides a method to generate a password that you can use for applications that need to relay mail. its different from the password that you would use to login through webmail.
Sign in to Google and start using App Passwords. This allows you to use a 16 digit password to access google services including ability to send out email. Refer below
https://support.google.com/accounts/answer/185833?hl=en
I am deploying a Django app on Heroku, and using the Sendgrid addon to send out validation email when a user registers on the site.
I followed the instructions here and pasted the following into settings.py:
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'sendgrid_username'
EMAIL_HOST_PASSWORD = 'sendgrid_password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
However, my app is crashing after registration.
What exactly am I supposed to put for EMAIL_HOST_USER and EMAIL_HOST_PASSWORD?
Under the developer's tab in the sendgrid addon in heroku, it gives me the username app*******#heroku.com, and for password it just says "Your Password". Is the password my Heroku password?
Also, do I need to include DEFAULT_FROM_EMAIL in my settings.py file? And where do I tell Sendgrid what it is?
EDIT: I've set DEBUG = True, and it looks like the error is:
SMTPSenderRefused
(550, 'Cannot receive from specified address <info#myapp.com>: Unauthenticated senders not allowed', 'info#myapp.com')
it looks like the problem is happening before Sendgrid does its thing. Do I need to authenticate the email address with Heroku somehow?
Within your settings.py include:
import os
EMAIL_HOST_USER = os.environ['SENDGRID_USERNAME']
EMAIL_HOST= 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = os.environ['SENDGRID_PASSWORD']
Edit: changed EMAIL_PASSWORD to EMAIL_HOST_PASSWORD as that's the correct spelling.
In the intervening 10 years, the above answer has become obsolete. Sendgrid now uses an API key.
https://docs.sendgrid.com/for-developers/sending-email/django
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey'
EMAIL_HOST_PASSWORD = SENDGRID_API_KEY
EMAIL_PORT = 587
EMAIL_USE_TLS = True