# Does DISCOURSE\_SMTP\_ADDRESS do MX lookup

**URL:** https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839
**Category:** Support
**Created:** [2016年一月12日 16:28 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839 "2016-01-12T16:28:57Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Blaisorblade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blaisorblade/32/107357_2.png) [@Blaisorblade](https://meta.discourse.org/u/Blaisorblade)
#### Post date: [2016年一月12日 16:28 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/1 "2016-01-12T16:28:57Z")

</div>

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 [ActionMailer::Base](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).

---

<div class="post-metadata">

### Author: ![Blaisorblade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blaisorblade/32/107357_2.png) [@Blaisorblade](https://meta.discourse.org/u/Blaisorblade)
#### Post date: [2016年一月12日 17:31 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/2 "2016-01-12T17:31:59Z")

</div>

For extra fun, I searched a bit more. [Action Mailer Basics — Ruby on Rails Guides](http://guides.rubyonrails.org/action_mailer_basics.html) 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](http://guides.rubyonrails.org/configuring.html#configuring-action-mailer) 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](https://github.com/rails/rails/blob/c4f8ce53b1f9af9585aeec9bbb0c66fc9c48ec1b/actionmailer/lib/action_mailer/delivery_methods.rb), then on Mail::SMTP ([docs](http://www.rubydoc.info/github/mikel/mail/master/Mail/SMTP)), then on Net::SMTP ([docs](http://ruby-doc.org/stdlib-2.0.0/libdoc/net/smtp/rdoc/Net/SMTP.html)). 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.

> <https://github.com/ruby/ruby/blob/3e92b635fb5422207b7bbdc924e292e51e21f040/lib/net/smtp.rb#L541-L554>

---

<div class="post-metadata">

### Author: ![calmh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/calmh/32/115466_2.png) [@calmh](https://meta.discourse.org/u/calmh)
#### Post date: [2016年一月12日 18:26 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/3 "2016-01-12T18:26:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Blaisorblade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blaisorblade/32/107357_2.png) [@Blaisorblade](https://meta.discourse.org/u/Blaisorblade)
#### Post date: [2016年一月12日 18:33 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/4 "2016-01-12T18:33:29Z")

</div>

> [@calmh](#):
>
> 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.

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 [http://serverfault.com/a/386880/29689](http://serverfault.com/a/386880/29689) (second part)? Do you know any reference I could use to convince him Ruby/Discourse does the right thing?

---

<div class="post-metadata">

### Author: ![calmh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/calmh/32/115466_2.png) [@calmh](https://meta.discourse.org/u/calmh)
#### Post date: [2016年一月12日 18:43 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/5 "2016-01-12T18:43:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kpfleming](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kpfleming/32/116414_2.png) [@kpfleming](https://meta.discourse.org/u/kpfleming)
#### Post date: [2016年一月12日 19:41 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/6 "2016-01-12T19:41:18Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [2016年一月13日 01:11 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/7 "2016-01-13T01:11:01Z")

</div>

> [@Blaisorblade](#):
>
> you’re implying my mail sysadmin is abusing MX records for load balancing of outgoing mail servers.

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](http://rationalwiki.org/wiki/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?”](https://www.google.com/support/enterprise/static/postini/docs/admin/en/activate/mx_faq.html#966971):

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

---

<div class="post-metadata">

### Author: ![Blaisorblade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blaisorblade/32/107357_2.png) [@Blaisorblade](https://meta.discourse.org/u/Blaisorblade)
#### Post date: [2016年一月15日 12:29 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/8 "2016-01-15T12:29:00Z")

</div>

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.

> [@kpfleming](#):
>
> i’ve never seen a widely deployed solution to address this problem

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.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年六月8日 12:45 UTC](https://meta.discourse.org/t/does-discourse-smtp-address-do-mx-lookup/37839/9 "2024-06-08T12:45:53Z")

</div>

此主题已在 3069 天后自动关闭。不再允许回复。
