1

I have a server with hostname and DNS example.com. I also have a google apps account for user@example.com. I have my MX records setup correctly and I can send and receive emails to and from user@example.com with my personal email.

On server example.com, I have some code sending email using sendmail to admin@example.com. I don't have any smtp configured with sendmail. I can send mail from server example.com to user@otherdomain.com, but when I try to send an email from server example.com to admin@example.com I get the following error in /var/log/maillog:

... while talking to [127.0.0.1]:
>>> DATA
<<< 550 5.1.1 <user@example.com>... User unknown
550 5.1.1 <user@example.com>... User unknown
<<< 503 5.0.0 Need RCPT (recipient)

I imagine this is because sendmail is receiving the email to user@example.com, and going "ah-ha! I'm example.com! I just need to send it to the user on this server." rather than looking at the MX records and seeing it needs to forward them to the gmail servers.

How can I tell sendmail to forward all messages off to the gmail servers irrespective of the domain?

Note: domains changed to example.com to protect the innocent.

2

The problem is - as you deduced - that your server's hostname is example.com making the MTA on that server think that any e-mail messages to @example.com should be delivered locally.

The quick solution is to simply change the hostname, e.g. call your server www.example.com.

Alternatively you use sendmail's MAIL_HUB feature to redirect local mail to another server: in the sendmail.mc macro file set:

define(`MAIL_HUB', `mailer:servername')

With that servername replaced by the hostname of your primary MX record. That will redirect messages send from your server to <username>@<hostname> i.e. drew@example.com to servername.

The actual answer to the question: "How can I tell sendmail to forward all messages off to the gmail servers irrespective of the domain?" is:
You don't want that. Gmail is not an open relay and will reject anything that's not handled locally.

The feature does exist and is called a SMART_HOST in sendmail jargon. That requires an outgoing smtp server specifically configured to relay for your ip-address (range) such as the outgoing SMTP server of your ISP.

define(`SMART_HOST', `smtp.your.provider')dnl
  • Sorry, I should clarify that questoin. If google is handling my MX records, how do I tell sendmail to deliver messages @example.com at my google servers. That is, sendmail does its normal delivery thing and finds the gmail servers through the MX records as it would or any other domain which is not example.com. – Drew Jul 21 '14 at 13:18
  • I ended up changing the hostname, but was still hoping to understand the problem a bit deeper – Drew Jul 21 '14 at 13:21
  • When I do this ALL email gets sent to the gmail. Even server emails from cron. I am not quite looking to do that. Anyway around this? – tylerism Aug 6 '15 at 17:59
3
  1. Name the host hostname.example.com (as reported by hostname --fqdn).
    The procedure is OS/distribution dependent.

  2. If example.com remains on list of local email domains then turn off auto-configuration of local email domains list.

Checking list of local email domains:
As root execute

echo $=w | sendmail -bt

Removing auto-configuration of local email domains list:
In sendmail.mc add the following line, recompile sendmail.cf and restart/reload sendmail daemon

define(`confDONT_PROBE_INTERFACES',`True')   

Local email domains may be explicitly listed in /etc/mail/local-host-names.

  • Thank you so much.... define(confDONT_PROBE_INTERFACES',True') worked great. Why and how does this work? – tylerism Aug 6 '15 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.