Can´t make msmtp MTA to use GPG password file via crontab
Hello,
I would love to count with any help on this matter, if possible.
I have set up msmtp in a Linode but can't make msmtp to use GPG password file.
I have successfully created my encryption key using gpg --gen-key
.
I have also created the password file, using:
gpg --encrypt -o ~/.msmtp-password.gpg -r my_email_address -
After that I added the below line to my ~/.msmtprc
file:
passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.msmtp-password.gpg"
And from now on I get to send emails from the command line (using echo "Message" | msmtp my_email@domain.com
.
But if I use a cron job the output e-mails from this are not sent.
Verifying the logs, I see that either the password file is not found or cannot be open, despite it being in its correct place (with the respective chmod 600 ~/.msmtp-password.gpg
to increase security).
Any idea why this does not work only in cron jobs?
Thanks in advance.
4 Replies
Any idea why this does not work only in cron jobs?
Because cron IS NOT bash! ~ is a bashism that cron knows nothing about.
-- sw
Use your the full path of your home directory everywhere you use ~.
Or, at the top of your script, define a shell variable:
home=/the/path/to/home
and use $home everywhere you use ~.
Of the two, the second method will be more maintainable.
— sw
P.S. You can’t depend on common environment variables (e.g, $HOME, $PATH, etc.) to be defined the way they would be in your login shell either, so it’s best to use the full path to any programs your job runs as well: /the/path/to/gpg.