Can I store my getmail password in a gpg file?

As far as I understand, getmail can get the password from

  1. from the password configuration item in the getmailrc file,
  2. from the OS X keychain (on macOS only),
  3. on systems with Gnome keyring support, from the default Gnome keyring,
  4. if not found via any of the above methods, getmail will prompt for the password when run.

(reference: http://pyropus.ca/software/getmail/configuration.html)

It seems to me that storing the password in a GnuPG encrypted file will require you to decrypt the file (using your GnuPG passphrase) and then somehow feed that into getmail while not storing it in a plain text file in-between (possibly using expect?).

It would be simpler, and less prone to accidentally leaving your mail password unencrypted somewhere, to just have getmail prompt you for the mail password (option 4 above).


Yes you can.

Add your key to gpg-agent or gnome-keyring, and configure either gpg -d or pass to write to stdout without prompting for key unlock. Mind to only include the password in the file. In ~/.getmail/getmailrc:

password_command = ("/usr/bin/pass","email/gmail.pw")

I installed getmail 5.5 from the official website instead of using the ubuntu-xenial repo (4.48) to get the password_command working.