Michael de Silva's Blog

Software Engineer. Rubyist and Roboticist.

Michael de Silva's Blog

Software Engineer. Rubyist and Roboticist.

HOWTO: Setup mail forwarding with Sendmail in Ubuntu 10.04 LTS

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


# Hosts with to allow relaying
virtualdomain.tld RELAY


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

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.

Ref: https://gist.github.com/1010125

comments powered by Disqus