Code

Opened 4 years ago

Last modified 3 years ago

#13570 assigned Bug

SMTP backend should try harder to figure out the local host name

Reported by: jacob Owned by: sernin
Component: Core (Mail) Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Django's SMTP backend sets the local_hostname argument to smtplib.SMTP by calling socket.getfqdn() (via django.core.mail.utils.DNS_NAME, which caches that result). smtplib itself uses a slightly more robust method (see smtplib around line 245) if local_hostname isn't given.

In certain circumstances this can mean that sending mail through smtplib directly works, but sending it via django.core.mail fails.

We could solve this by just passing local_hostname=None, but that'd result in a DNS lookup every time we send email, which is silly (and which is why we're caching it in the first place).

So, DNS_NAME should use similar logic to smtplib to try harder to get the DNS hostname.

Attachments (1)

ticket13570.diff (823 bytes) - added by sernin 4 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by sernin

  • Owner changed from nobody to sernin
  • Status changed from new to assigned

Changed 4 years ago by sernin

comment:3 Changed 4 years ago by sernin

  • Has patch set

comment:4 Changed 4 years ago by anonymous

Forgot to comment -- but trivial patch attached, copies the logic from python's standard smtplib. Should be ready for checkin but this is my first contribution so I'll leave this as-is (Accepted, has_patch).

comment:5 Changed 4 years ago by claudep

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 3 years ago by russellm

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

Sorry - but this isn't RFC.

It doesn't contain a test case, and it doesn't contain a compelling argument for why tests aren't plausible. It doesn't even contain a clear description of why the change is needed other than suggesting "certain circumstances" under which it will be needed.

It also seems to assume that the result of socket.gethostbyname(socket.gethostname()) will be an IPv6 address, which I'm pretty sure isn't correct.

comment:7 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:8 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:11 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:12 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from sernin to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.