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

Re: [msmtp-users] pre-connect?



Jim Pryor wrote:

> On Sat, May 22, 2010 at 01:50:36PM -0400, John Eikenberry wrote:
> > I currently use esmtp's preconnect functionality to ssh to my work's mail
> > server and send out email. They use SPF so I can't spoof and they don't
> > support remote SMTP connections. The ssh tunnel works fine and I have been
> > happy with it. But now I'm looking to switch MTAs due to unrelated
> > problems.
> > 
> > msmtp looks almost perfect except for the lack of pre-connect like
> > functionality to establish the ssh tunnel for the smtp connection. I can't
> > seem to find it in the docs but thought I'd check here in case I missed it
> > or if someone had some alternative approach they could suggest.
> 
> There may be a better way than this, but if nothing emerges, what's
> wrong with something like this...
> 
> #!/bin/bash
> 
> ssh -set -up -your -tunnel &
> SSH_PID=$!
> sleep 1     # I'm sure there's a better way...
> if [ -d /proc/$SSH_PID ]; then
>     # ...but at this point, we can assume the ssh tunnel is up
>     # and we know the PID of its process, so...
>     msmtp "$@" # receives stdin
>     killall $SSH_PID
> fi
 
Yeah, I'd thought of something like that. Was hoping for something better.
BTW you don't need the sleep if you use ssh with '-f' which forks _after_
the ssh connection has been established, but before running the command.
You just pass it 'sleep 5' as the command to keep the connection open long
enough to kick off msmtp.

You can also just put that ssh command in the if test and don't have to
worry about killing it as it will go away automatically after 5 seconds or
after msmtp finishes (an open socket over the tunnel keeps it open).

-- 

John Eikenberry
[jae@...230... - http://zhar.net]
[PGP public key @ http://zhar.net/jae_at_zhar_net.gpg]
______________________________________________________________
"Perfection is attained, not when no more can be added, but when no more 
 can be removed." -- Antoine de Saint-Exupery

Attachment: signature.asc
Description: Digital signature