Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify name in Django mail?

I am using django's core.mail package in conjunction with django-registration for a new user sign up workflow. I have an email account, "no-reply@(mycompany).com" through my company's google mail service, that i want to use to send these emails. In the google mail account settings i set the name for the email account as "(MyCompany) Support" so that if I mail directly from google mail, the emails come in from the account as being from "(MyCompany) Support ". However, when i use django's email settings to send mail, the emails show up in a client's email box as being from "no-reply" which is ugly and may be a bit off-putting to a new client. Is there a way to specify a "Name" for an email address when sending using django's built-in mailer so that the see the "Name" displayed when they get the email?

Here are my current settings in settings.py:

EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=587
EMAIL_HOST_USER='[email protected]'
EMAIL_HOST_PASSWORD='**********'
EMAIL_USE_TLS = True
like image 910
B Robster Avatar asked Mar 28 '12 16:03

B Robster


People also ask

What is SMTP in Django?

Although Python provides a mail sending interface via the smtplib module, Django provides a couple of light wrappers over it. These wrappers are provided to make sending email extra quick, to help test email sending during development, and to provide support for platforms that can't use SMTP.

How do I send multiple emails in Django?

How to send multiple mass emails django. We need to create a Tuple of messages and send them using send mass mail. In this tutorial, we create a project which sends email using Django. We fill the data in the form and send it using Django Email.


2 Answers

You can use

"(MyCompany) Support <[email protected]>"

as the from address in the call to send_mail.

like image 91
RotaJota Avatar answered Oct 18 '22 21:10

RotaJota


Those solutions are useful if you're using django's email package directly. However, i didn't want to look for a hook to override the way that django-registration uses send_mail so I found the following setting when going through the django files, which lets you set a default from email.

 DEFAULT_FROM_EMAIL='(My Company) Support <[email protected]>' 

and it worked!

Figured someone else may find it useful, although i'm not so pretentious as to mark my own answer as correct.

like image 43
B Robster Avatar answered Oct 18 '22 22:10

B Robster