Sunday, February 25, 2007

Cygwin and fetchmail

I've been a frequent user of both Cywgin and fetchmail for rather a long time.

For a project I'm working on, I found that it would be very useful to be able to download messages from Gmail to shell scripts running under Windows. So, that means getting fetchmail to work under Cygwin.

This article gives you a pretty quick and easy overview of how to get fetchmail running under Cywgin. Problem is, it doesn't work. Not on fetchmail on my laptop, anyway.

I kept getting an error: "nodename nor servname provided, or not known" whenever running fetchmail with fetchmail -v (the -v meaning verbose -- I recommend always calling fetchmail with -v)

After a bit of Googling, here's what I found: You need to add the following to the /etc/services file on Cygwin:
pop3s 995/tcp

The error message is apparently specific to sites that require SSL to connect. The wording apparently indicates that fetchmail and Cygwin don't know how to establish a POP3 SSL connection, because it's not specified in the services list with a port entry. After I did that, it worked like a charm.

Here's another tip. Check out my .fetchmailrc file:
poll proto pop3 and options no dns
user '' password 'pwgoeshere' options keep ssl
fetchlimit 1
mda "/usr/bin/tee incoming.txt > /dev/null"

Note some of the things I've changed around here. I set "fetchlimit 1" which downloads only one message at a time, and I set an "mda" setting. This stands for "mail delivery agent." It's made for forwarding inbound mail to some other script or process, like procmail. Here I'm tricking it by using the "tee" command (which simply takes stdin and outputs it to both stdout and the file specified) to take the inbound piece of mail and put it in the file incoming.txt. I added the "> /dev/null" to not bother with the stdout output.

Remove the word "keep" if you don't want it to leave the mail on the server. (I'm using the "keep" option just for testing. I'll have to remove it as I move forward.)

There's probably a fancier way to take a single email via pop3 and put it into a text file for further processing; but this quick and dirty method is serving me well.

If you find any of this information useful, please let me know!

1 comment:

Chris Cera said...

Thank you very much for this post. I was able to get it working thanks to your help. I'm left wondering why these aren't already listed in /etc/services since it would seem like a harmless addition.