6

I'd like mutt (mutt-kz, actually -- I'd love to migrate to neomutt but that's a bigger project) to get my SMTP password from pass so I don't have to keep it stored in cleartext in my config file, but I'm not sure how to properly pass the password into my .muttrc.

This is what I have in .muttrc:

source ~/.mutt/pass.sh|
set smtp_pass = $my_pass

And then .mutt/pass.sh contains:

#! /bin/bash
my_pass=$(pass Example/user)

If I add echo ${my_pass} to pass.sh and run it from the command line, it does echo my password.

When I launch mutt-kz I'm prompted to unlock my pass gpg key, so something is working, but when I try to send mail from Mutt it asks for my SMTP password and fails if I don't provide it the message isn't sent: ("SASL authentication failed")

So ... how do I correctly pass the variable from my shell script to my .muttrc?

2 Answers 2

4

The program ~/.mutt/pass.sh must produce output that looks like

set my_pass = swordfish

So it can be something like

#!/bin/sh
echo "set my_pass = swordfish"

Note that if your password contains certain special characters (\'" and whitespace), you'll need to quote it. For example, if your password is in the text file ~/passwords/smtp.txt, you can use:

#!/bin/sh
~/passwords/smtp.txt sed 's/["$`\\]/\\&/g; s/^/set my_pass = "/; s/$/"/'

For the password sword\fish, this prints set my_pass="sword\\fish".

If you use Gnome-keyring to store your passwords then you can use the secret-tool utility to read your password from the keyring. For example, this is what I use for an Office 365 password (with a password that doesn't contain any special character that needs quoting):

source 'printf "set imap_pass="; secret-tool lookup action_url https://login.microsoftonline.com/common/login |'
1
  • secret-tool requires even number of arguments. Commented Nov 3, 2021 at 14:44
3

The other possibility would be use of backtick expansion. So you should be able to do:

my_pass = `pass Example/user`

If you migrate to neomutt eventually you could also define variable with command line, i.e.

my_pass=$(pass Example/user) mutt

and then you can use my_pass variable as in your example.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.