﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6989	Inability to define DNS_NAME in django.core.mail results in e-mail messages being rejected or marked as spam	Franklin	Jacob Rief	"'''Summary'''[[BR]]
Being the case that the application server's hostname may not necessarily be a valid fully qualified domain name (FQDN) the use of socket.getfqdn() in defining DNS_NAME may yield a number of e-mail messages either rejected or marked as spam. Rejection issues arise if settings.EMAIL_USE_TLS is True - meaning smtplib.ehlo() will be called - and if a mail server is particularly strict (or misconfigured) and rejects any ehlo command followed by an invalid FQDN. Spam issues arise with DNS_NAME being used as the local_hostname argument to smtplib.SMTP() within the SMTPConnection.open() method, meaning the initial ""Received:"" e-mail header may be from an invalid FQDN. Further increasing the chance of being marked as spam is DNS_NAME being used by the make_msgid() method, leaving the ""Message-ID:"" e-mail header ending in an invalid FQDN.

'''Real World Scenario'''[[BR]]
A shared server has a hostname, which you may not and can not change, of ""star-wars-reference"". The socket.getfqdn() method fails to find info on its IP address and by default simply returns said hostname. E-mail is then sent by Django with a Message-ID of ""200804....@star-wars-reference"" from a server claiming to be ""star-wars-reference ([server's IP address])"" and is, of course, marked as spam.

'''Solution'''[[BR]]
Provide an optional settings variable such as EMAIL_LOCAL_HOSTNAME where Django developers may define a FQDN which maps to their application's server. EMAIL_LOCAL_HOSTNAME will be used by the class defining DNS_NAME in lieu of socket.getfqdn() if EMAIL_LOCAL_HOSTNAME exists in the settings file (this has the added benefit of preventing a call to socket.getfqdn() - further reducing overhead on restarts)."	Bug	assigned	Core (Mail)	dev	Normal		local_hostname, DNS_NAME, CachedDnsName, smtplib, SMTPConnection	jeremy+django@… davidgrant@…	Accepted	1	1	0	1	0	0
