I tested Django send_mail() function which I needed for a project. I had the EMAIL_HOST set to the SMTP server provider my company uses, EMAIL_PORT to 587, EMAIL_USE_TLS to True. Both EMAIL_HOST_USER and EMAIL_HOST_PASSWORD was set to "" (empty string).
Then I used the send_mail as:
from djanog.core import mail
mail.send_mail(
"Django mail sample",
"Body",
"myemail#example.com",
["myemail#example.com"]
)
But calling the view actually sent the email to my mail from my mail, but I didn't provide any password at all. I also set recipient_list to my colleague's mail, it worked. Then I tried to change the from_email to my colleague's mail it didn't work.
I have my mail setup in Thunderbird in my system.
So how did Django sent the mail without my email's password? Was it because of my setup in Thunderbird? What happened exactly?
Update:
My colleague tried the same in his system, which doesn't have any mail configured. When running the result was an SMTPRecipientsRefused.
I used both my Phone's network as Hotspot and my company's Hotspot both worked. But in my colleague's system nothing worked.
When setting EMAIL_USER_HOST and EMAIL_HOST_PASSWORD in my colleague's system it worked.
Related
I am trying to request a reset password from a system deployed on heroku but i get this error.
SMTPAuthenticationError at /password-reset/
(534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbs\n5.7.14 i1cE5v2I-3UUFLl6jQMnBfbcvZuRiGo_q9k1T5h2XgMGxtKYIJ0sIPE9Jr6zW1X78xQM3\n5.7.14 Py7mrOXSPkPG01upxjbZRi68aLrKIbvG_4uHrli9l7ZVmFnr8CxRNb9JUDGVcm8M>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 k188sm1479373qkd.98 - gsmtp')
I have set all these settings and they seem to be okay but i still get the same error. Kindly help
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
Your application is probably fine, but the issue is with Google, that is preventing your login as it is a potentially suspicious activity. You may have received a mail from Google telling you that a suspicious activity has happened.
To solve this problem, you have to change your Google's security settings and create an app password so you can login from your application:
Using a browser, login to your Gmail account
Go to "Manage your account"
Go to "Security"
In "Signing to Google" section, click on "App passwords"
Enter your password
In "Select the app and device you want to generate the app password for.", select Other, name it anyway you want and click "Generate"
Use this password in Django instead of your regular password.
I used to be able to do this, not sure why it seems to no longer work. I want Django to email me whenever an error occurs like 500 server error, which would be useful since the email usually includes the detailed error description.
Here's one error I'm letting persist for now shown in chrome's terminal as I try and get this feature to work.
here's what I have in my settings file
ADMINS = ['<my_email>']
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = SERVER_EMAIL = '<server_email>'
EMAIL_HOST_PASSWORD = "xxxxxx" #
EMAIL_USE_TLS = True
so even though this is an error it doesn't send any emails to my mail.
I can however send emails from the shell using
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'<server_email>',
['<my_email>'],
fail_silently=False,
)
from the same server
ADMINS settings need to be a list of tuples with name and email in each tuple.
Example : ADMINS = [('John', 'john#example.com'), ('Mary', 'mary#example.com')]
Reference : https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-ADMINS
Is there any way to send a verification email. when an user registers through drf (Django Rest framework). I have this code in my User model:
from django.core.mail import send_mail
from config import settings
def email_user(self, subject, message, from_email=settings.DEFAULT_FROM_EMAIL, **kwargs):
send_mail(subject, message, from_email, [self.email], fail_silently=False, **kwargs)
and in my settings.py:
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = '`132312123'
EMAIL_HOST_USER = 'mimic#gmail.com'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
But email not being sent, also I want to verification email service, so user will be activated when they click on the link. How to accomplish these?
If you look here:
Console backend
Instead of sending out real emails the console backend just writes the
emails that would be sent to the standard output. By default, the
console backend writes to stdout. You can use a different stream-like
object by providing the stream keyword argument when constructing the
connection.
Also:
This backend is not intended for use in production – it is provided as
a convenience that can be used during development.
Try this one instead:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
I have an html page with a form where I collect some data like mail_sender, mesage_to_send, subject etc.
When a user click on a button that information is submitted to a views.py function:
from django.core.mail import send_mail
def register_new_request(request):
email_person = request.POST.get('email_person', False)
send_mail('Test', 'Here is the message.', email_person,['tosomeone#example.com'], fail_silently=False)
return HttpResponseRedirect("/")
How i configure in my settings.py to send email to lotus notes via that function?
After some research i found that are some variables that need to be configured like :
EMAIL_USE_TLS = True
EMAIL_HOST = ''
EMAIL_PORT = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
Can tell me someone how exactly should look that variables? Thanks !
django.core.email sends SMTP mail. There is absolutely nothing special about sending SMTP email to Lotus Notes users. It looks exactly like sending email to any other email user on the Internet.
If your real question is about sending to a Lotus Notes user from within that user's internal network, presumably by submitting your SMTP message directly to a Lotus Domino server, then you need to talk to the administrator(s) responsible for the servers and find out (a) if SMTP is enabled on at least one internal Domino server, (b) what host and port to use to connect via SMTP to the Domino server, (c) is SSL/TLS supported or required for the SMTP connection to the Domino server (d) whether authentication is required, and if yes what user name and password your code should use.
I am using the Gmail SMTP server to send out emails from users of my website.
These are the default settings in my settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'example#example.com'
EMAIL_HOST_PASSWORD = 'pwd'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
SERVER_EMAIL = EMAIL_HOST_USER
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
If I want a user to send an email, I am overriding these settings and sending the email using Django's email sending methods. When an exception occurs in the system, I receive an email from the example#example.com. Sometimes I receive an email from some logged in user. Which could also possibly mean that when a user receives an email sent from my website it has a sent address different from the actual user.
What should be done to avoid this situation?
Django only uses settings.DEFAULT_FROM_EMAIL when any of the mail sending functions pass None or empty string as the sender address. This can be verified in django/core/mail.py.
When there is an unhandled exception Django calls the mail_admins() function in django/core/mail.py which always uses settings.SERVER_EMAIL and is only sent to addresses listed in settings.ADMINS. This can also be verified in django/core/mail.py.
The only other place Django itself sends e-mails is if settings.SEND_BROKEN_LINK_EMAILS is True, then CommonMiddleware will send mail to all addresses listed in settings.MANAGERS and the e-mail sender is settings.SERVER_EMAIL.
Therefore, the only time a regular user will receive e-mail from your site is when you call send_mail(). So, always pass a real address as the from_mail argument and you will avoid users receiving email from settings.SERVER_EMAIL or settings.DEFAULT_FROM_EMAIL.
Side note: django-registration is at least one example of a Django pluggable that will send mail from settings.DEFAULT_FROM_EMAIL so in cases like this you need to make sure it is a proper e-mail address such as support#yoursite.com or webmaster#yoursite.com.