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

I think I understood. Do you have an idea about how do I needed to proceed here?

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.

Ah, now I understood. My bad, sorry.

Everything is working fine now.

Thank you very much.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct