We encountered an issue recently with Devise’s password reset emails. The sender address on the emails appeared as “sender@debian” rather than “sender@ourdomain.com”, despite the fact that we had configured Devise to use a specific address:

# config/initializers/devise.rb
Devise.setup do |config|
(...)
  config.mailer_sender = "Sender Name <sender@ourdomain.com>"
(...)
end

Interestingly, we did not have this issue with any other emails sent by the application, only the ones generated by Devise.

The server running this app is a Debian 6 (“squeeze”) box, running Sendmail.

The problem was a setting at the bottom of the Sendmail configuration file (/etc/mail/sendmail.mc).

The final lines of this file, before modification, were:

dnl # Masquerading options
FEATURE(`always_add_domain')dnl
MASQUERADE_AS(`debian')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl

This is the source of the “@debian” domain that was being used instead of the one we set in the application. For a simple fix, we just changed the MASQUERADE_AS setting to match the domain we wished to send from:

dnl # Masquerading options
MASQUERADE_AS(`ourdomain.com')dnl

With that, the Devise mails finally matched our application’s domain.