Does DISCOURSE_SMTP_ADDRESS do MX lookup

What’s the content of DISCOURSE_SMTP_ADDRESS? Is it the actual hostname of the SMTP server, or can Discourse perform an MX lookup? I do need Discourse to do the MX lookup, and couldn’t find any actual info in docs, even though I tracked this down to http://api.rubyonrails.org/classes/ActionMailer/Base.html. Docs mostly just talk of SMTP credentials. (For comparison, Postfix gives control over this behavior, while MSMTP just doesn’t support MX lookup on the relay host).

Unfortunately I can’t even try this out for now on my staging Discourse instance — it runs on the same physical server (our only one), and I can’t touch this because Docker/AUFS are causing not-yet-diagnosed instabilities: stopping my production Discourse instance fails and leaves it unusable until rebooting the host. (No, not my lucky day — and it was a bad idea to trust Docker to actually be robust).

For extra fun, I searched a bit more. Action Mailer Basics — Ruby on Rails Guides says:

For a complete writeup of possible configurations see the Configuring Action Mailer in our Configuring Rails Applications guide.

But Configuring Rails Applications — Ruby on Rails Guides still only has:

:address - Allows you to use a remote mail server. Just change it from its default “localhost” setting.

Finally, I ended up on
rails/actionmailer/lib/action_mailer/delivery_methods.rb at c4f8ce53b1f9af9585aeec9bbb0c66fc9c48ec1b · rails/rails · GitHub, then on Mail::SMTP (docs), then on Net::SMTP (docs). Both the docs and (especially) the sources of this last library suggest no MX lookup is done. If none of the many wrappers do that, my sysadmin won’t be happy.

1 Like

MX lookups get the mail server name(s) for a given domain found in an email address. It is not used to resolve the IP of an outgoing mail server. You need to put the host name or IP of your outgoing mail server in that config setting.

3 Likes

I don’t distrust you, but you’re implying my mail sysadmin is abusing MX records for load balancing of outgoing mail servers. Is he supposed to use multiple A records for smtp, like in linux - Load Balance Mail Gateways - Server Fault (second part)? Do you know any reference I could use to convince him Ruby/Discourse does the right thing?

If he’s doing that, then he’s abusing MX records, yes. I suggest searching for best practice guides for mail configuration. Using MX records for outgoing mail from clients won’t be in them.

1 Like

i’ve never seen a widely deployed solution to address this problem, so finding one that is automatically supported by client software is unlikely. If you wanted to create one, the proper solution would be to use SRV records for the Mail Submission Agent (port 587) method of submitting outbound mail.

No implication, no “abuse” of MX records: your mail sysadmin is straight-up-and-down doing it wrong. MX records are “mail exchange” records. Specifying the outgoing relay MTA in an MUA (which Discourse is) is not something that MX records are involved in. I’m not aware of any MUA which performs MX record lookups on the name configured as the outgoing relay MTA. Even stub MTAs (which are a curious hybrid) like ssmtp don’t do MX record lookups on relay names.

As for references, there’s a good chance that the backfire effect is going to bite you, but if anyone will be convincing, it should be Google, with their answer to the question, “What is an MX record?”:

Each MX record points to an email server that’s configured to process mail for that domain.

So, an MX record for outgoing.example.com says, "the MTA you can contact by talking to the name in this MX record will accept mail addressed to <anyone>@outgoing.example.com`. It does not say anything about that MTA’s willingness to accept, forward, fold, spindle, or mutilate mail for any other domain.

6 Likes

Thanks to all responses.

My sysadmin might have conceded the point, but I think he had concerns on A records; his advise was to point Discourse to a local MTA (Postfix) that’s able to deal with MX lookup and relaying. Since I had to set up Postfix anyway (or, well, to switch from MSMTP to Postfix), I’ll probably do that.

It also seems that Postfix’s default behavior (looking up MX by default on relay hosts) might be wrong, but I won’t try figuring that out.

Well, people suggest a DNS entry for a hostname like smtp.yourdomain.com with multiple A records pointing to the different hosts — though that doesn’t work extremely well.

This topic was automatically closed after 3069 days. New replies are no longer allowed.