Opened 18 years ago

Closed 17 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: dev
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

Description

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@…> 18 years ago.

Download all attachments as: .zip

Change History (6)

by Fraser Nevett <mail@…>, 18 years ago

Attachment: hostname.diff added

comment:1 by Adrian Holovaty, 18 years ago

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 by Maximillian Dornseif <md@…>, 18 years ago

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 global_settings.py .

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 by Fraser Nevett <mail@…>, 18 years ago

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 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:5 by Jacob, 17 years ago

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