Take the 2-minute tour ×

Currently,I am using gmail's smtp and Django send_mail.

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'sample@gmail.com'
EMAIL_HOST_PASSWORD = 'samplepass'

Whenever I use django's send mail, the sender is always based on the EMAIL_HOST_USER (in this case, sample@gmail.com).

What I want to happen is to modify the sender so that it will not use sample@gmail.com, instead it will use an email from the contact_email_address field in my Business_Profile Model.

class Business_Profile(models.Model):   
    contact_email_address = models.EmailField()

Is there a way for this to happen? I don't want to add an email_address_password field in my Business_Profile class.

If it's not possible, I am open to suggestions such as using an email server. I have a production server running on nginx and I've heard of postfix. Can I achieve what I want using postfix? Or are there better and easy-touse mail servers instead of postfix?

Thanks for reading. This is my first time to ask a question.

share|improve this question
add comment

1 Answer

You can give the sender address as a parameter to send_mail():

from django.core.mail import send_mail

profile = BusinessProfile.objects.get(pk=1)

send_mail('Subject here', 'Here is the message.', profile.contact_email_address,
    ['to@example.com'], fail_silently=False)

Read more at https://docs.djangoproject.com/en/dev/topics/email/.

share|improve this answer
Hi! Thanks for the reply. I tried your solution, but it still used the EMAIL_HOST_USER specified in the settings.py which is sample@gmail.com. –  patty Dec 9 '11 at 6:58
Could the problem be that you're using Gmail's SMTP server? Gmail probably only allows you to send mail with authorized addresses. Check that you have the sender address listed at mail.google.com/mail/u/0/#settings/accounts –  Visa Kopu Dec 9 '11 at 7:34
Yeah, I think what I want is not possible using gmail's server. I've read from other sources that custom senders are not allowed because they can be used for spamming. However I still hope there are other ways aside of using mail servers. Thanks for replying! –  patty Dec 9 '11 at 7:46
add comment

Your Answer


