Skip to contentSkip to conversation

git send-email SMTP password command

DISCUSSION Jeremy Baxter 2 participants 3 messages Jun 16, 2024 – Jun 24, 2024

lore
Share & tools
lore
#0 lore raw

Hi list, I was wondering if it's possible to configure send-email's default SMTP client to execute a shell command and capture its output to get the SMTP password rather than prompting the user on the terminal.

Would anyone know if this is possible without setting sendemail.sendmailCmd?

Thanks,

Jeremy

#1 lore raw
Quoted 6 lines · Jeremy Baxter

Hi list, I was wondering if it's possible to configure send-email's default SMTP client to execute a shell command and capture its output to get the SMTP password rather than prompting the user on the terminal.

Would anyone know if this is possible without setting sendemail.sendmailCmd?

You can use a credential helper, and that can be a shell command. For example, you can do this:

  git -c credential.helper= \
      -c credential.helper='!f(){ echo username="$USER"; echo password="$PASS";};f' send-email ...

This resets the list of credential helpers (with the empty value) to remove any you may have already set, and then uses that shell script to read the credentials from the environment. The documentation on the protocol is in git-credentials(1) and gitcredentials(7).

You can also use your regular credential helper to store the credentials, in which case you need not set any -c options at all.

Note that, in general, this only works for SASL authentication that uses usernames and passwords (e.g., PLAIN, SCRAM-SHA-256, etc.), and not things like GSSAPI (Kerberos), but you also don't need a credential helper for GSSAPI.

Signature · 2 lines
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
#2 lore raw
Quoted 6 lines · brian m. carlson

You can use a credential helper, and that can be a shell command. For example, you can do this:

  git -c credential.helper= \
      -c credential.helper='!f(){ echo username="$USER"; echo password="$PASS";};f' send-email ...
Quoted 7 lines

This resets the list of credential helpers (with the empty value) to remove any you may have already set, and then uses that shell script to read the credentials from the environment. The documentation on the protocol is in git-credentials(1) and gitcredentials(7).

You can also use your regular credential helper to store the credentials, in which case you need not set any -c options at all.

Excellent, that's working for me now. Thanks a lot!

Jeremy