git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 2/2] send-email: enable copying emails to an IMAP folder without actually sending them

From
Aditya Garg <gargaditya08@live.com>
Date
Aug 12, 2025, 06:44 UTC
Message-ID
<PN3PR01MB95976EFF4DA2B0BB479E2113B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
In-Reply-To
<PN3PR01MB9597E8E33868386C997D2563B82BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>

`git imap-send` was built on the idea of copying emails to an IMAP folder like drafts, and sending them later using an email client. Currently the only way to do it is by piping output of `git format-patch` to IMAP send.

Add another way to do it by using `git send-email` with the `--use-imap-only` or `sendmail.useImapOnly` option. This allows users to use the advanced features of `git send-email` like tweaking Cc: list programmatically, compose the cover letter, etc. and then send the well formatted emails to an IMAP folder using `git imap-send`.

While at it, use `` instead of '' for --smtp-encryption ssl in help section of `git send-email`.

Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
 Documentation/config/sendemail.adoc |  1 +
 Documentation/git-send-email.adoc   | 14 ++++++++++++++
 git-send-email.perl                 |  9 ++++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/sendemail.adoc b/Documentation/config/sendemail.adoc
index dd2dbc87a0..90164c734d 100644
--- a/Documentation/config/sendemail.adoc
+++ b/Documentation/config/sendemail.adoc
@@ -89,6 +89,7 @@ sendemail.smtpServerPort::
 sendemail.smtpServerOption::
 sendemail.smtpUser::
 sendemail.imapSentFolder::
+sendemail.useImapOnly::
 sendemail.thread::
 sendemail.transferEncoding::
 sendemail.validate::
diff --git a/Documentation/git-send-email.adoc b/Documentation/git-send-email.adoc
index d1c41a0dbd..a385f865fb 100644
--- a/Documentation/git-send-email.adoc
+++ b/Documentation/git-send-email.adoc
@@ -311,6 +311,20 @@ must be used for each option.
 This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
 for instructions.
 
+--use-imap-only::
+--no-use-imap-only::
+	If this is set, all emails will only be copied to the IMAP folder specified
+	with `--imap-sent-folder` or `sendemail.imapSentFolder` and will not be sent
+	to the recipients. Useful if you just want to create a draft of the emails
+	and use another email client to send them.
+	If disabled with `--no-use-imap-only`, the emails will be sent like usual.
+	Disabled by default, but the `sendemail.useImapOnly` configuration
+	variable can be used to enable it.
+
++
+This feature requires setting up `git imap-send`. See linkgit:git-imap-send[1]
+for instructions.
+
 --batch-size=<num>::
 	Some email servers (e.g. 'smtp.163.com') limit the number of emails to be
 	sent per session (connection) and this will lead to a failure when
diff --git a/git-send-email.perl b/git-send-email.perl
index b3cc237baa..96504e7be1 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -62,7 +62,7 @@ sub usage {
     --smtp-user             <str>  * Username for SMTP-AUTH.
     --smtp-pass             <str>  * Password for SMTP-AUTH; not necessary.
     --smtp-encryption       <str>  * tls or ssl; anything else disables.
-    --smtp-ssl                     * Deprecated. Use '--smtp-encryption ssl'.
+    --smtp-ssl                     * Deprecated. Use `--smtp-encryption ssl`.
     --smtp-ssl-cert-path    <str>  * Path to ca-certificates (either directory or file).
                                      Pass an empty string to disable certificate
                                      verification.
@@ -75,6 +75,8 @@ sub usage {
     --smtp-debug            <0|1>  * Disable, enable Net::SMTP debug.
     --imap-sent-folder      <str>  * IMAP folder where a copy of the emails should be sent.
                                      Make sure `git imap-send` is set up to use this feature.
+    --[no-]use-imap-only           * Only copy emails to the IMAP folder specified by
+                                     `--imap-sent-folder` instead of actually sending them.
 
     --batch-size            <int>  * send max <int> message per connection.
     --relogin-delay         <int>  * delay <int> seconds between two successive login.
@@ -296,6 +298,7 @@ sub do_edit {
 my $target_xfer_encoding = 'auto';
 my $forbid_sendmail_variables = 1;
 my $outlook_id_fix = 'auto';
+my $use_imap_only = 0;
 
 my %config_bool_settings = (
     "thread" => \$thread,
@@ -312,6 +315,7 @@ sub do_edit {
     "forbidsendmailvariables" => \$forbid_sendmail_variables,
     "mailmap" => \$mailmap,
     "outlookidfix" => \$outlook_id_fix,
+    "useimaponly" => \$use_imap_only,
 );
 
 my %config_settings = (
@@ -532,6 +536,7 @@ sub config_regexp {
 		    "smtp-auth=s" => \$smtp_auth,
 		    "no-smtp-auth" => sub {$smtp_auth = 'none'},
 		    "imap-sent-folder=s" => \$imap_sent_folder,
+		    "use-imap-only!" => \$use_imap_only,
 		    "annotate!" => \$annotate,
 		    "compose" => \$compose,
 		    "quiet" => \$quiet,
@@ -1683,6 +1688,8 @@ sub send_message {
 
 	if ($dry_run) {
 		# We don't want to send the email.
+	} elsif ($use_imap_only) {
+		die __("The destination IMAP folder is not properly defined.") if !defined $imap_sent_folder;
 	} elsif (defined $sendmail_cmd || file_name_is_absolute($smtp_server)) {
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
-- 
2.50.1
Previous: Aditya GargNext: Junio C Hamano
Message 31 of 33 in “send-email: add ability to send a copy of sent emails to an IMAP folder”
  1. send-email: add ability to send a copy of sent emails to an IMAP folderAditya Garg, Jul 20, 2025
  2. send-email: add ability to send a copy of sent emails to an IMAP folderAditya Garg, Jul 21, 2025
  3. Eric SunshineJul 21, 2025
  4. Aditya GargJul 23, 2025
  5. Junio C HamanoJul 21, 2025
  6. brian m. carlsonJul 22, 2025
  7. Aditya GargJul 22, 2025
  8. Aditya GargJul 22, 2025
  9. Junio C HamanoJul 22, 2025
  10. Aditya GargJul 22, 2025
  11. Aditya GargJul 22, 2025
  12. Junio C HamanoJul 22, 2025
  13. Aditya GargJul 22, 2025
  14. Aditya GargJul 22, 2025
  15. Junio C HamanoJul 22, 2025
  16. Aditya GargJul 22, 2025
  17. Junio C HamanoJul 22, 2025
  18. Aditya GargJul 22, 2025
  19. send-email: add ability to send a copy of sent emails to an IMAP folderAditya Garg, Jul 22, 2025
  20. Aditya GargJul 23, 2025
  21. 0/2 send-email: integrate with git imap-sendAditya Garg, Jul 23, 2025
  22. 1/2 send-email: add ability to send a copy of sent emails to an IMAP folderAditya Garg, Jul 23, 2025
  23. 2/2 send-email: enable copying emails to IMAP folder without actually sending themAditya Garg, Jul 23, 2025
  24. Junio C HamanoAug 11, 2025
  25. Aditya GargAug 12, 2025
  26. Aditya GargAug 12, 2025
  27. Junio C HamanoAug 12, 2025
  28. Aditya GargAug 12, 2025
  29. 0/2 send-email: integrate with git imap-sendAditya Garg, Aug 12, 2025
  30. 1/2 send-email: add ability to send a copy of sent emails to an IMAP folderAditya Garg, Aug 12, 2025
  31. 2/2 send-email: enable copying emails to an IMAP folder without actually sending themAditya Garg, Aug 12, 2025
  32. Junio C HamanoAug 12, 2025
  33. Junio C HamanoAug 15, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.