0

I use msmtp as the sendmail program on my Ubuntu 18.04 system. Rather than have the password of smtp service sitting in the clear in my msmtprc file, I have written a small ruby program that I call "authinfo" that takes a hostname on the command line, finds its password in ~/.authinfo.gpg, decrypted it, and echos it to stdout.

This works great if I run msmtp from the command line.

However, when cron runs it to send email about a cron command, it fails, with the following in the log file:

Jul 16 16:01:01 micah CRON[19482]: (ded) CMD (bash -l -c 'env >&2 && exit 2')
Jul 16 16:01:05 micah cron[1486]: Cannot read from file '/.authinfo.gpg'.
Jul 16 16:01:05 micah cron[1486]: sendmail: cannot read output of '/home/ded/bin/authinfo smtp.gmail.com'
Jul 16 16:01:05 micah CRON[19481]: (ded) MAIL (mailed 1846 bytes of output but got status 0x004e from MTA#012)

It seems it cannot read the stdout of my authinfo program. This is different from a command run from the sixth field of a crontab command, which is affected by the SHELL and PATH environment settings in the crontab file. I', guessing the way sendmail is run is hard-coded into cron. Somehow, it is not letting sendmail/msmtp get the output of the passowrdeval program from the .msmtprc file.

Any ideas as to why?

0

1 Answer 1

0

In case someone else comes across this, I figured out the issue after posting my question. The cron process running sendmail (aka msmtp) is not running under my username. Hence, my authinfo program which defaulted to a file name of "ENV['HOME']/.authinfo.gpg" had no HOME set in the environment, so it was looking in /.authinfo.gpg, which does not exist.

Hence the error. The solution was to allow my authinfo program to take a fully-expanded path to the authinfo file as a commandline parameter. After doing so, it ran as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .