How to specify a name in Django mail?

I am using the django core.mail package in conjunction with django registration for a new user registration workflow. I have an "no-reply @ (mycompany) .com" email account through my Google email service that I want to use to send these emails. In the google mail account settings, I set the name of the email account as "(MyCompany) Support", so if I send mail directly from Google mail, emails come from the account from "(MyCompany) Support". However, when I use django's email settings to send mail, emails appear in the client’s inbox as “unanswered”, which is ugly and might be a little delayed for a new client. Is there a way to specify a “Name” for an email address when sending using the django built-in mail program to see the “Name” displayed when receiving email?

Here are my current settings in settings.py:

EMAIL_HOST='smtp.gmail.com' EMAIL_PORT=587 EMAIL_HOST_USER=' no-reply@mycompany.com ' EMAIL_HOST_PASSWORD='**********' EMAIL_USE_TLS = True 
+6
source share
4 answers

you can use

 "(MyCompany) Support < no-reply@mycompany.com >" 

as from the address in the send_mail call.

+22
source

These solutions are useful if you use the django email package directly. However, I did not want to look for a hook to override the way django-registration uses send_mail, so I found the following option when viewing django files, which allows you to set the default from email.

  DEFAULT_FROM_EMAIL='(My Company) Support < no-reply@mycompany.com >' 

and it worked!

I realized that someone else might find this useful, although I'm not so pretentious as to correctly indicate my own answer.

+12
source

You can use the ADMINS and MANAGERS in setting.py . For instance:.

 ADMINS = (('Your Name', ' email@company.com ),) 

And then:

 django.core.email.mail_managers('subject', 'body') 
+2
source

DEFAULT_FROM_EMAIL = '(My company) Support

Helped me solve the problem.

+1
source

Source: https://habr.com/ru/post/911873/


All Articles