Re: [Django] #6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages being rejected or marked as spam

17 views
Skip to first unread message

Django

unread,
Jul 15, 2013, 11:17:21 AM7/15/13
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, | Needs documentation: 1
SMTPConnection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Edwin):

Here is a workaround.

Python's socket.getfqdn() resolution process works like this on Linux:
1. Get hostname of server.
2. Resolve IP address for hostname.
3. Resolve name for IP address.
4. If 2 or 3 fail, just use the hostname.

Therefore, if you add a line like this to your /etc/hosts,
socket.getfqdn() will resolve myhostname to 127.0.0.1 and resolve
127.0.0.1 to myfqdn since that is the first name in the list. You also
have to make sure that there are no other entries for 127.0.0.1 on
previous lines.

{{{
127.0.0.1 myfqdn myhostname
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 4, 2013, 1:31:53 AM9/4/13
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, | Needs documentation: 1
SMTPConnection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

That workaround only makes sense if the server is hosting one django
project. I have one Linux server with several django projects. Each uses a
different fqdn but the same IP.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:12>

Django

unread,
Sep 4, 2013, 1:33:03 AM9/4/13
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, | Needs documentation: 1
SMTPConnection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by davidgrant@…):

Can we get this in? Relying on socket.get_fqdn() seems very wrong and
patch looks good.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:13>

Django

unread,
Sep 21, 2013, 1:24:49 AM9/21/13
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, | Needs documentation: 1
SMTPConnection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by davidgrant@…):

So where do we go from here? Instead of a setting we could use an
environment variable. Other than that I don't see any other way.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:14>

Django

unread,
Sep 21, 2013, 1:25:40 AM9/21/13
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, | Needs documentation: 1
SMTPConnection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by davidgrant@…):

* cc: davidgrant@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:15>

Django

unread,
Sep 21, 2013, 3:55:11 AM9/21/13
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, | Needs documentation: 1
SMTPConnection | Patch needs improvement: 1
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by russellm):

@davidgrant - Where do we go? We go the same way we do with any other
ticket that has stalled: Start a discussion on django-dev. Summarize the
problem. Summarize the alternatives. Propose a solution.

I'll also note that Adrian's comment about settings -- we've historically
avoided adding new settings wherever possible. But if it truly isn't
possible (at all, or for all practical purposes) to avoid a setting, it's
not completely off the cards.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:16>

Django

unread,
Feb 17, 2017, 1:34:47 PM2/17/17
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I think a setting is fine considering we added other mail settings
recently. The patch needs to be updated, checked against the
PatchReviewChecklist, and turned into a pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:17>

Django

unread,
Apr 5, 2017, 12:23:05 PM4/5/17
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: heathervm
Type: Bug | Status: assigned

Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by heathervm):

* owner: nobody => heathervm
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:18>

Django

unread,
Jun 13, 2018, 8:11:02 AM6/13/18
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: heathervm
Type: Bug | Status: assigned
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Diederik van der Boor):

Python's smtplib.SMTP code works around this problem with a fallback to
the IP address::


{{{
# RFC 2821 says we should use the fqdn in the EHLO/HELO verb,
and
# if that can't be calculated, that we should use a domain
literal
# instead (essentially an encoded IP address like [A.B.C.D]).
fqdn = socket.getfqdn()
if '.' in fqdn:
self.local_hostname = fqdn
else:
# We can't find an fqdn hostname, so use a domain literal
addr = '127.0.0.1'
try:
addr = socket.gethostbyname(socket.gethostname())
except socket.gaierror:
pass
self.local_hostname = '[%s]' % addr
}}}

This is overwritten as Django's
`django.core.mail.backens.smtp.EmailBackend` overwrites this to:

`connection_params = {'local_hostname': DNS_NAME.get_fqdn()}`

One possible extra fix would be to support the same fallback to IP-
addresses when there is no dot in the hostname, just like
`smtplib.SMTP.open()` does.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:19>

Django

unread,
Jun 13, 2018, 8:12:09 AM6/13/18
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: heathervm
Type: Bug | Status: assigned
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Diederik van der Boor):

To add, this issue also happens on Kubernetes pods.

A standard Pod on Kubernetes has the following configuration:

**/etc/hosts**

{{{
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.244.1.204 examplepod-77f687b9b9-5hlsg
}}}

**/etc/resolv.conf**

{{{
nameserver 10.96.0.10
search NAMESPACE.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
}}}

Hence email is submitted using `EHLO examplepod-77f687b9b9-5hlsg` and thus
triggering spam filtering.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:20>

Django

unread,
Apr 4, 2019, 5:08:53 AM4/4/19
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: heathervm
Type: Bug | Status: assigned
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Diederik van der Boor):

I bumbed into this again, in the end I had to fix this by patching:

`django.core.mail.utils.DNS_NAME._fqdn = "my.desired.host"`

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:21>

Django

unread,
Nov 27, 2020, 3:21:15 PM11/27/20
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: Jacob
| Rief

Type: Bug | Status: assigned
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Rief):

* owner: heathervm => Jacob Rief


Comment:

Pull request to add this feature:
https://github.com/django/django/pull/13728

However as a configuration directive I used EMAIL_MESSAGEID_FQDN because
to me, that's more meaningful.
I'm open to discussions on the naming of this.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:22>

Django

unread,
Jan 12, 2024, 12:43:59 AMJan 12
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: Jacob
| Rief
Type: Bug | Status: assigned
Component: Core (Mail) | Version: dev

Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Alexander Lazarević):

I'm trying to understand the status of this ticket and the problem. I
traced the discussion here, on the PR and google groups ...

The end of the discussion in google groups seems to be:

{{{
Jacob Rief 31 Jan 2022, 15:36:40 to Django developers (Contributions to
Django itself)
On Monday, January 31, 2022 at 7:55:47 AM UTC+1 f.apo...@gmail.com wrote:

Okay then,

some of the things like sender reputation and different bounce hooks
came to my mind as well, but it is good to hear confirmation from others.
I think the next steps would be to create a new ticket to add support for
*multiple* email backends and then work from that (I would only link the
old ticket since it's scope was mainly putting the config into a dict as
opposed to multiple backends). Given that there are plenty of +1 here
already I think we already have our implementors? :)

Some items that I like to see addressed in a PR:
* Backwards compat
* Similarity to Caches & Databases (ie so we don't invent yet another
syntax)
* Support for connection aliases (default/…) in send_email % friends
(basically everything taking a connection now should probably take aliases
as well)

OK. Since I made the proposal, it then is probably up to me to create the
ticket.


Mariusz Felisiak 1 Jun 2023, 21:48:04 to Django developers (Contributions
to Django itself)

It seems we have a consensus here to support multiple email backends.
Jacob, feel-free to create a new ticket.

Best, Mariusz
}}}

I couldn't find the Ticket by Jacob or anyone related to this.

A related ticket #31885 got fixed and closed. In the description it is
said that "We will then recommend subclassing in the docs for more
control. "

Is subclassing now also the proposed method for setting a custom DNS_NAME
(or other option)? (I does not seemed to be mentioned in the docs)

Is the support for multiple email backends abandoned for now?

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:23>

Django

unread,
Jan 12, 2024, 2:24:06 AMJan 12
to django-...@googlegroups.com
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages
being rejected or marked as spam
-------------------------------------+-------------------------------------
Reporter: Franklin | Owner: Jacob
| Rief
Type: Bug | Status: assigned
Component: Core (Mail) | Version: dev
Severity: Normal | Resolution:
Keywords: local_hostname, | Triage Stage: Accepted
DNS_NAME, CachedDnsName, smtplib, |
SMTPConnection |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:23 Alexander Lazarević]:


> Is subclassing now also the proposed method for setting a custom
DNS_NAME (or other option)? (I does not seemed to be mentioned in the
docs)

Yes, subclassing is basically a way to go for any fancy change to the
`EmailBackend` behavior.

> Is the support for multiple email backends abandoned for now?

Not really, it looks like no one had time to create a ticket. Please do if
you want.

--
Ticket URL: <https://code.djangoproject.com/ticket/6989#comment:24>

Reply all
Reply to author
Forward
0 new messages