Opened 12 years ago

Closed 11 years ago

#2858 closed enhancement (wontfix)

[patch] Better default value for SERVER_EMAIL

Reported by: Fraser Nevett <mail@…> Owned by: nobody
Component: Core (Other) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Neither mail_managers() nor mail_admins() allow you to specify the address from which their email should be sent, but instead use the value of SERVER_EMAIL from the settings file. This is fine, but the default is 'root@localhost'.

Some MTAs (such as Postfix) will automatically append a domain suffix to this, as it knows that 'localhost' won't resolve on the Internet and it tries to convert it into a fully qualified hostname (e.g. 'root@localhost' would become 'root@…').

As such a hostname will not usually exist, some email servers will reject messages from this sender as it assumes that it is a spoofed address.

Obviously, an easy solution is just to define SERVER_EMAIL to something sensible in your settings file! However, should you neglect (or forget) do do this, it would be nice if Django had a default value that was more likely to be a real email address.

The attached patch defines this variable using the machine's hostname.

A similar issue exists with DEFAULT_FROM_EMAIL, which the patch also addresses.

Attachments (1)

hostname.diff (1.2 KB) - added by Fraser Nevett <mail@…> 12 years ago.

Download all attachments as: .zip

Change History (6)

Changed 12 years ago by Fraser Nevett <mail@…>

Attachment: hostname.diff added

comment:1 Changed 12 years ago by Adrian Holovaty

Using this level of Python code in the settings file (importing the socket module, and calling a function from it) makes me slightly uncomfortable. On the other hand, it may be acceptable as long as we employ rock-solid exception handling. Anybody else have thoughts on the matter?

comment:2 Changed 12 years ago by Maximillian Dornseif <md@…>

gethostbyname() is a relatively save network function. It does not block like so many other functions in the socket module, so I see no risk that django hangs for minutes while processing .

I'm all for the patch, least but not least because it is good Internet citizenship to avoid sending out mails from non-existant addresses.

comment:3 Changed 12 years ago by Fraser Nevett <mail@…>

After reading some more of the socket module documentation, I notice there is a socket.getfqdn() function that returns a fully qualified domain name. Perhaps this is preferable to socket.gethostname()?

Also, as you're rightly concerned about ensuring robust exception handling in such a core part of Django, would it be sensible to move the import socket statement to within the try block, or would that just be overkill?

comment:4 Changed 12 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedDesign decision needed

comment:5 Changed 11 years ago by Jacob

Resolution: wontfix
Status: newclosed

Though root@socket.getfqdn (or whatever) might help email work a bit better out of the box, it usually isn't any more "correct" than root@localhost. I've never set up a Django instance where I haven't had to edit SERVER_EMAIL. Given that, I'd rather have a somewhat silly default so that folks wil understand that this is a setting they need to look at if they want email to work correctly.

Note: See TracTickets for help on using tickets.
Back to Top