Unable to get send_mail to send an email message Django - django

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?

Related

How can I get Django to send error emails on status codes above 500?

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.

Django sendmail SMTPDataError

I am getting the below error while trying to use Django sendmail using Outlook SMTP
SMTPDataError at /distribute/
(554, '5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message
Cannot submit message. 16.55847:0C0F0000,
17.43559:0000000094000000000000000000000000000000, 20.52176:140F0E852800101064010000, 20.50032:140F0E858817101069010000, 0.35180:0A00E781, 255.23226:6E010000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A000000, 16.55847:86000000, 17.43559:0000000068010000000000000000000000000000, 20.52176:140F0E85280010100A00F736, 20.50032:140F0E85881710100A00F836, 0.35180:8C010000, 255.23226:40000730, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:0A001780, 4.21921:DC040000, 255.27962:FA000000, 255.1494:A4010000, 0.37692:05000780, 0.37948:00000000, 5.33852:00000000534D545000000780, 4.56248:DC040000, 7.40748:010000000000010B05000780, 7.57132:000000000000000005000780, 1.63016:32000000, 4.39640:DC040000, 8.45434:824D851FB0676A47B811311E3F17990F00000000, 5.10786:0000000031352E32302E313239342E3032343A5455345052383430314D42303436323A34333038323065332D393530612D346435362D383863332D3037363837616130336664330005000780,
255.1750:0A008984, 255.31418:41010000, 0.22753:0A001986, 255.21817:DC040000, 4.60547:DC040000, 0.21966:4B010000, 4.30158:DC040000 [Hostname=TU4PR8401MB0462.NAMPRD84.PROD.OUTLOOK.COM]')
My settings are as below:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = '********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 587
Please help
I had an error similar to yours, and I resolved it as follows, two points that I think you have to pay attention to are:
EMAIL_HOST normally email hosts have this format ** smtp.nameserver.com **, example:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.outlook.com'
EMAIL_HOST_USER = '********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 587
When sending the email, the send_mail method has to send the email from an address in your domain, example:
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from#outlook.com', # pay attention here I had a problem because of that
['to#example.com'],
fail_silently=False,
)

Email send in django

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

Django send_mail not working with gmail

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

Setting up email with Sendgrid in Heroku for a Django App

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