Why can’t I echo the password to fetchmail

command linefetchmailpassword

I'm trying to configure a fetchmail. Before I deal with the syntax of fetchmailrc ( I discovered that the level of bugginess of a problem is synergistic with the number of different aspects of the problem that I do not understand, so one new thing at a time ), I decided to pass all the options via commandline.

I got tired of entering the password for each test so I wanted to pass it in the script. I couldn't find something like –pass as a commandline option for fetchmail so I thought maybe echo the password to fetchmail ala:

echo "dohadeer"| fetchmail  --all -p pop3 -k pop.gmail.com --ssl -d0   --user FakeName@gmail.com

I dismissed it and googled "fetchmail password commandline" and got several hits which claimed the above technique worked! But when I tried it I get the error:

fetchmail: can't find a password for FakeName@gmail.com@pop.gmail.com.

I can figure out workarounds for the original problem, but I can't figure out why this approach doesn't work. Obviously there is something I don't understand about Linux and want to figure out.

Best Answer

The reason for the given error message is that fetchmail has its standard input not attached to a terminal, but a pipe.

man fetchmail | less -Ip 'user authentication step failed'

# from: 
# http://opensource.apple.com/source/fetchmail/fetchmail-33/fetchmail/fetchmail.c

...
if (!isatty(0))   // <-- tests if stdin is a terminal (added)
{
   fprintf(stderr,
      GT_("fetchmail: can't find a password for %s@%s.\n"),
         ctl->remotename, ctl->server.pollname);
         return(PS_AUTHFAIL);
         } else {
...

You may, however, try the following script hack to let fetchmailrun in a pseudo terminal.

(sleep 0.3; echo "dohadeer") | 
( script -q /dev/null fetchmail --all -p pop3 -k pop.gmail.com --ssl -d0 --user FakeName@gmail.com )
Related Question