views:

323

answers:

2

I am sending emails to users using Django through Google Apps.

When the user receives emails sent from the Django app, they are from:
[email protected]

when looking at all emails in the inbox, people see the email's sender as :
do_not_reply or [email protected] depending on the email client used

If I log into that "do_not_reply" account using the browser and Google Apps itself and then send an email to myself, the emails are from:
Dont Reply<[email protected]>

As a result, the name displayed for the email's sender in the inbox is:
Dont Reply

In Django, is there a way to attach a "name" to the email account being used to send emails?

I have reviewed Django's mail.py, but had no luck finding a solution
http://code.djangoproject.com/browser/django/trunk/django/core/mail.py?rev=5548

Using:
Django 1.1
Python 2.6
Ubuntu 9.1
settings.EMAIL_HOST = 'smtp.gmail.com'

Thanks

A: 

Hi

I use this code to send through gmail smtp (using google apps). and sender names are OK

def send_mail_gapps(message, user, pwd, to):
    import smtplib
    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
    mailServer.ehlo()
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(user, pwd)
    mailServer.sendmail(user, to, message.as_string())
    mailServer.close()
jujule
This is actually the same code that Django's EmailMessage classes uses in the background. Regardless, I tried your method and the email still has `do_not_reply` as the sender's name. Thanks for trying though
cadwag
and what about settings.DEFAULT_EMAIL_FROM ?
jujule
+4  A: 

You can actually use "Dont Reply <[email protected]>" as the email address you send from.

Try this in the shell of your django project to test if it also works with gapps:

>>> from django.core.mail import send_mail
>>> send_mail('subject', 'message', 'Dont Reply <[email protected]>', ['[email protected]'])
Gregor Müllegger
Thanks for posting! Wish I had seen this yesterday b/c it would have saved me some time. I was just reading the documentation over at <http://docs.djangoproject.com/en/dev/topics/email/#emailmessage-objects> and finally read the "from_email" more closely and found the same answer as you. Was just coming here to post an answer when I saw yours. Anyway, thanks again! Glad to finally have this working
cadwag