Thursday, February 28, 2008

command line email in Cygwin

As mailx is not part of the Cygwin distribution, you don't have that many choices if you want to send an email from a shell script. In this regard, Jeremy Reed has kindly provided a nice substitute script that can help us out:
http://cygwin.com/ml/cygwin/2005-02/msg00635.html

If you have Cygwin installed, you'll need to do the following things:
1) install ssmtp
2) configure ssmtp with ssmtp-config
3) install Jeremy's mailx shell programs

There are a couple of gotchas with step 2 above.
1) make sure you have the directory /etc/ssmtp created
- for some reason, the ssmtp-config program doesn't create it
2) make sure you define a fully qualified hostname
- if not, you'll get the following error
$ /usr/bin/mailx -s "test" cacasododom@gmail.com < test.txt
3) make sure that you have a symbolic link created for /usr/sbin/sendmail that links to /usr/sbin/ssmtp and that /usr/sbin is in your PATH. Otherwise, you'll get this error:
$ mailx.sh -s "test" joe.user@yahoo.com < test.txt

That's it.

I preferred to use Jeremy's program over nail, because it gives me the same arguments as mailx did.

Thanks Jeremy!
TAG

2 comments:

mikeehamm said...

Does anyone know of a way to install the fdisk linux utility into Cygwin as it is not included in the installation setup?

Cacasodo said...

Mike,
According to these threads from the Cygwin mailing list:
http://cygwin.com/ml/cygwin/2001-04/msg01050.html

http://cygwin.com/ml/cygwin/2001-04/msg01096.html

it seems that for specific technical reasons, Cygwin does not port fdisk, essentially because it works at a lower level in the OS than the Cygwin toolset.

Methinks you're out of luck,
'sodo

Feel free to drop me a line or ask me a question.