IMHO, the easiest way to do this is with postfix. You can configure it as a light outgoing relay with these commands:
postconf -e relayhost=other.mailserver.com
postconf -e myorigin=my.domainname.com
As long as the SMTP server specified in
relayhost doesn't require authentication, allows you to relay or is a valid destination for the recipient address this will work.
myorigin parameter will be the default domain name. So if you send mail to foo it will go to [email protected]. Mail sent by user bar will be from [email protected].
If you do need to authenticate and want to support TLS, also run the following commands:
postconf -e smtp_tls_security_level=may
postconf -e smtp_sasl_auth_enable=yes
postconf -e smtp_sasl_password_maps=pcre:/etc/postfix/sasl_password_maps
/etc/postfix/sasl_password_maps have this content:
All mail will be sent to your relayhost with the specified username and password.