[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using a remote IMAP server and smarthost



On Sat, Aug 25, 2007 at 22:09:58 +0100, Richard Lyons wrote:
> On Sat, August 25, 2007 18:56, Florian Kulzer wrote:
> > On Sat, Aug 25, 2007 at 17:30:12 +0100, Richard Lyons wrote:
> [...]
> >> I have an IMAP server on a remote vm.  I access it with mutt because it
> >> sucks least.  But when I want to send mail, I have to open a webmail
> [...]
> 
> > Can you log in on the vm via ssh? Is a sendmail-equivalent command
> > available to you there? There are various tricks that can be played with
> > ssh tunneling and/or with remotely running sendmail via ssh. (I'll be
> > happy to provide more details if an ssh-based approach is feasible for
> > you.)
> 
> Yes, no problem with ssh.  I have also tried simply using mutt on
> the server, which works but has two disadvantages: I cannot copy mail
> to the local machine, and for presumably different reasons of
> misconfiguration that also cannot send mail!  But the tunnelling sounds
> a good way forward.  I did try installing stunnel once, but the guide
> I was referring to was not up to my level of ignorance.
> 
> Please do tell me more...

OK, I will outline the two methods I know, then you can decide which one
you like better. (Don't hesitate to ask for more details if necessary.)

In the following I will assume that your ~/.ssh/config is set up such
that you can use "ssh myvm" to log in on the vm. (This allows me to keep
the command syntax simple and in any case I think it is a good approach
in practice.) I would also recommend to set up public key authentication
and to use ssh-agent, to avoid having to type your password whenever you
send mail.



Method 1:
---------

You can forward a local port via ssh like this:

ssh -N -L 2525:smtp.smarthost.tld:25 myvm

This command establishes an ssh connection to myvm. Everything that is
sent to port 2525 on your local computer will be forwarded to myvm and
then myvm will pass it on to smtp.smarthost.tld, port 25. This is like a
mini-VPN for only one port; you have to run this command before you send
mail(s) and you can cancel it (CTRL-C) when you are done. Mutt (or any
other MUA) on the local computer can now simply be configured to use
localhost, port 2525 as its smtp server. To smtp.smarthost.tld, on the
other hand, it will seem as if the smtp-connection originates from myvm
and it should accept it. The connection works in both directions and all
reactions of the smarthost will be sent back to your local computer,
port 2525.

If the smarthost requires smtps connections from myvm then you have to
use port 465 instead of port 25:

ssh -N -L 2525:smtp.smarthost.tld:465 myvm

and you have to configure mutt or your local MTA accordingly.



Method 2:
---------

You can set up mutt's sendmail command to use a short script which
invokes ssh to run sendmail on myvm directly. This requires that
sendmail works on myvm, though. The advantage is that you don't have to
do anything else before you send mail (unlike with method 1). It seems
that you do not have sendmail fully operational on myvm at the moment,
so maybe you will want to stick with method 1 right now. In any case,
here is the necessary wrapper script for method 2:

---------- STARTS BELOW (this line is not part of the script) ----------
#! /bin/sh
# sendmail-via-ssh.sh
# wrapper script for mutt to use sendmail via ssh
#
# activated by this option in ~/.muttrc:
# set sendmail="/path/to/sendmail-via-ssh.sh"

cat - | ssh myvm "/usr/sbin/sendmail -oem -oi $@"
---------- ENDS ABOVE (this line is not part of the script) ----------

-- 
Regards,            | http://users.icfo.es/Florian.Kulzer
          Florian   |



Reply to: