Prepare SSH
Locally, create a new SSH key without password. In these examples, it will be located at /etc/mail/ssh-sendmail-key and owned by the MAILUSER user. Change MAILUSER to whatever Unix account your local system uses: postfix, sendmail, mail, ... Using root or nobody is not recommended.
# ssh-keygen -f /etc/mail/ssh-sendmail-key -N ""
# chown MAILUSER /etc/mail/ssh-sendmail-key{,.pub}
Append the contents of /etc/mail/ssh-sendmail-key.pub to the server's authorized_keys file:
ssh-rsa AAAA....
Postfix
Create a ssh transport in master.cf:
ssh unix - n n - - pipe
user=MAILUSER argv=/usr/bin/ssh -i /etc/mail/ssh-sendmail-key myhostserver /usr/sbin/sendmail -i $recipient
In main.cf, add:
default_transport = ssh
Exim
Router:
ssh:
driver = manualroute
domains = ! +local_domains
transport = ssh
route_list = * foo
Transport:
ssh:
driver = pipe
user = MAILUSER
command = /usr/bin/ssh -i /etc/mail/ssh-sendmail-key myhostserver /usr/sbin/sendmail -i $RECIPIENT