Configuring mutt to send e-mail over an SSH tunnel

Using remote SMTP is described here: https://gitlab.com/muttmua/mutt/-/wikis/MuttFaq/Sendmail

So with the tunnel you'd set up your SMTP to localhost, but with the tunnel port. Eg. you create tunnel 8025->25 on remote:

ssh -L8025:smtp.example.com:25 serv.example.com

And in Mutt configuration (.muttrc) you put:

set smtp_url="smtp://username@localhost:8025/"

BTW. Using remote POP/IMAP here: https://gitlab.com/muttmua/mutt/-/wikis/MuttFaq/RemoteFolder


You don't need to have ssh with local port forwarding running on your own. Both mutt and Neomutt have config option tunnel.

  • mutt docs
  • neomutt docs

tunnel
Type: string
Default: (empty)

Setting this variable will cause mutt to open a pipe to a command instead of a raw socket. You may be able to use this to set up preauthenticated connections to your IMAP/POP3/SMTP server. Example:

set tunnel="ssh -q mailhost.net /usr/local/libexec/imapd"

Note: For this example to work you must be able to log in to the remote machine without having to enter a password.

When set, Mutt uses the tunnel for all remote connections. Please see “account-hook” in the manual for how to use different tunnel commands per connection.

example:

neomutt -F /dev/null \
  -e 'set tunnel="ssh host.example.com' \
  [email protected] \
  < /tmp/msg