2

Using git 2.5.

Is there a clever, or official, way to verify that git send-email is able to connect to, and authenticate with, my smtp server? I've configured git, but I don't seem to be able to successfully use git send-email.

When I execute git send-email [email protected] I either see:

[Net::SMTP] Connection closed at /usr/libexec/git-core/git-send-email line 1348.

Or, when using tls in my config, I see:

Died at /usr/libexec/git-core/git-send-email line 1348.

My ~/.gitconfig seems correct:

[user]
  name = John Jacob Jingleheimer Schmidt
  email = [email protected]
[sendemail]
  smtpserver = mail.example.com
  smtpuser = *****
  smtpserverport = **
  confirm = auto
  smtpauth = PLAIN
  smtpencryption = tls

This is a pain in the arse to troubleshoot. Is there some kind of git send-email --verify command that can sanely tell me that my config is sound?

2 Answers 2

2

Git 2.33 (Q3 2021), proposes another way to use/debug sendmail: "git send-email"(man) learned the --sendmail-cmd command line option and the sendemail.sendmailCmd configuration variable, which is a more sensible approach than the current way of repurposing the "smtp-server" that is meant to name the server to instead name the command to talk to the server.

So you can specify your own sendmail-like program, which can be used to debug/put more traces.

See commit cd5b33f (14 May 2021) by Gregory Anders (gpanders).
(Merged by Junio C Hamano -- gitster -- in commit 1359972, 14 Jun 2021)

git-send-email: add option to specify sendmail command

Signed-off-by: Gregory Anders

The sendemail.smtpServer configuration option and --smtp-server command line option both support using a sendmail-like program to send emails by specifying an absolute file path.
However, this is not ideal for the following reasons:

  1. It overloads the meaning of smtpServer (now a program is being used for the server?)
  2. It doesn't allow for non-absolute paths, arguments, or arbitrary scripting

Requiring an absolute path is bad for portability, as the same program may be in different locations on different systems.
If a user wishes to pass arguments to their program, they have to use the smtpServerOption option, which is cumbersome (as it must be repeated for each option) and doesn't adhere to normal Git conventions.

Introduce a new configuration option sendemail.sendmailCmd as well as a command line option --sendmail-cmd that can be used to specify a command (with or without arguments) or shell expression to run to send email.
The name of this option is consistent with --to-cmd and --cc-cmd.
This invocation honors the user's $PATH so that absolute paths are not necessary.
Arbitrary shell expressions are also supported, allowing users to do basic scripting.

Give this option a higher precedence over --smtp-server and sendemail.smtpServer, as the new interface is more flexible.
For backward compatibility, continue to support absolute paths in --smtp-server and sendemail.smtpServer.

git send-email now includes in its man page:

--sendmail-cmd=<command>

Specify a command to run to send the email.
The command should be sendmail-like; specifically, it must support the -i option.
The command will be executed in the shell if necessary.
Default is the value of sendemail.sendmailcmd.
If unspecified, and if --smtp-server is also unspecified, git-send-email will search for sendmail in /usr/sbin, /usr/lib and $PATH.

git send-email now includes in its man page:

For backward compatibility, this option can also specify a full pathname of a sendmail-like program instead; the program must support the -i option.
This method does not support passing arguments or using plain command names.
For those use cases, consider using --sendmail-cmd instead.

1
  • 1
    This should be the accepted answer. On my machine, I have setup msmtp, which works, unlike git send-email. By setting sendemail.sendmailCmd = msmtp -a [email protected] I was finally able to get this working. Thanks! Commented Aug 28, 2021 at 17:55
0

Use the --smtp-debug=1 option. This allows seeing the smtp communication output.

Not the answer you're looking for? Browse other questions tagged or ask your own question.