Skip to content

Instantly share code, notes, and snippets.

@egantz
Forked from bsodmike/howto.md
Created August 30, 2017 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egantz/8788cf3441a617ad0d13ec3a9ba878c4 to your computer and use it in GitHub Desktop.
Save egantz/8788cf3441a617ad0d13ec3a9ba878c4 to your computer and use it in GitHub Desktop.
HOWTO: Setup mail forwarding with Sendmail in Ubuntu 10.04 LTS

Copyright (c) 2011, Michael de Silva (michael@mwdesilva.com) Blog: http://www.bsodmike.com ~ Twitter: @bsodmike

Fix: 'config error: mail loops back to me (MX problem?)'

To prevent receiving config error: mail loops back to me (MX problem?) errors, you need to add each virtualdomain.tld to the /etc/mail/local-host-names file and re-compile your sendmail config via make.

You have asked mail to a domain (e.g., domain.net) to be forwarded to a specific host (in this case, relay.domain.net) by using an MX record, but the relay machine doesn't recognise itself as domain.net. Add domain.net to /etc/mail/local-host-names [known as /etc/sendmail.cw prior to version 8.10] (if you are using FEATURE(`use_cw_file')) or add "Cw domain.net" to your configuration file.

Source: http://www.sendmail.com/sm/open_source/support/support_faq/general_issues_faq/#4.5


Perform the following to enable email forwarding from the virtual domain virtualdomain.tld to another email address (in this example, jdoe@gmail.com). There are no local accounts associated - the aliases file has been left untouched.

Note that the hostname of the system this was performed on is different to virtualdomain.tld; typically, this should be the case for you as well (that's the whole point of virtual hosts; default will be bound to whatever VPS provided access domain defined in hostname).

/etc/mail/access

# Hosts with to allow relaying
virtualdomain.tld RELAY

/etc/mail/sendmail.mc

Remove ", Addr=" clauses to receive from any interface. Do this with caution as this opens up your MTA to be abused by spammers if you're not careful. /etc/mail/access needs to be setup carefully to ensure it rejects any domains apart from your own.

dnl DAEMON_OPTIONS(`Family=inet6, Name=MTA-v6, Port=smtp, Addr=::1')dnl
DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp')dnl

Add the following

dnl # Define virtualusertable
FEATURE(`virtusertable', `hash /etc/mail/virtusertable')dnl
VIRTUSER_DOMAIN_FILE(`/etc/mail/virtual-domains')dnl

Create virtusertable and add

jdoe@virtualdomain.tld     jdoe@gmail.com

Perform make and /etc/init.d/sendmail reload to restart the daemon. You can debug the relaying action by watching the log file by doing tail -f /var/log/mail.log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment