Search code examples
linuxsshsendmailmuttfetchmail

ssh tunnel for sendmail


I'm going nuts here, trying to get my system configured.

I have a laptop at home and a workstation at work. I use mutt and sendmail. I have a home ISP that is on a lot of blacklists, so that any email I send from my laptop through my ISP is frequently blocked as spam by the receiver. I can SSH to my workstation and use mutt there interactively, but it is slow and tedious. I download my email from the work server to the laptop with fetchmail.

I've tried to get the laptop to send mail through the work mailer using

ssh -L 25:workstation.work.com:25 workstation.work.com

but it seems that sendmail cannot be running when I do this. When I try to fetchmail from workstation to the laptop sendmail must be running on the laptop for the mail to be delivered locally at the laptop. When mail does go through it gets rejected because the hostname is not recognised. I've tried changing the hostname in mutt. This appears not to affect anything.

So I'm confused about how to configure mutt, sendmail and SSH on my laptop, so that I can compose and send emails from my laptop such that they get delivered, yet I also want to get my emails from the server with fetchmail and have it delivered locally.

Any help appreciated.


Solution

  • If you run that ssh tunnel, you can't be running sendmail locally because otherwise it will be listening on port 25, not your tunnel. And fetchmail by default wants a local mail server to deliver to, although you could configure it to deliver to an mbox file directly if you prefer.

    What I do instead is I run postfix on my laptop, and have it set up to deliver mail to localhost:2526 using relayhost=[127.0.0.1]:2526 in /etc/postfix/main.cf. Then I run the ssh tunnel ssh -N -L 2526:localhost:25 ptomblin@myserver so that when postfix goes to deliver, it tunnels out through the tunnel. And local mail clients like mutt and fetchmail see a local mail server running on port 25 like they expect.