Linux – relay to external network smtp server using sendmail as mta

linuxredhatsendmail

I am banging my head on desk for this.
My linux system is on local network where as my smtp server is on different network.
Is there any way that I can relay mails from my local machine to this remote smtp server to send mails ?
My apologies if I sound stupid or if it's very easy to do so. 🙁

Here is what I have done so far:
setup my local machine to send outbound mails by setting
SMART_HOST as my smtp server ( smtp.xxx.com ) in sendmail.cf
but i guess this exercise works when relaying for hosts on internal networks.
And my smtp server ( smtp.xxx.com ) is on external network to my local machine.
Do I need to update my sendmail configuration to relay to external network?

Best Answer

There are multiple ways to do it:

  • Configure an actual SMTP relay.
  • Use a VPN.
  • Use an ssh port forwarding.

The quickest to get started with is the ssh port forwarding, which in its simplest form could look like this: ssh -f -N -L '25:[::1]:25' -o ExitOnForwardFailure=true user@host.example.com

It is not the most reliable solution, as the ssh connection can die for a number of different reasons. More detailed advice would require more knowledge about your network. For example we would need to know, why the clients cannot connect directly to the SMTP server on the other network.