From: xiaoqiang zhao <zxq_yx_007@163.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, viktorin@rehivetech.com, mst@kernel.org,
pbonzini@redhat.com, mina86@mina86.com, artagnon@gmail.com,
avarab@gmail.com
Subject: [PATCH v5] send-email: --batch-size to work around some SMTP server limit
Date: Sun, 21 May 2017 20:59:50 +0800 [thread overview]
Message-ID: <20170521125950.5524-1-zxq_yx_007@163.com> (raw)
Some email servers (e.g. smtp.163.com) limit the number emails to be
sent per session(connection) and this will lead to a faliure when
sending many messages.
Teach send-email to disconnect after sending a number of messages
(configurable via the --batch-size=<num> option), wait for a few
seconds (configurable via the --relogin-delay=<seconds> option) and
reconnect, to work around such a limit.
Also add this two configuration option.
Note:
Re-authentication will happen every $<batch-size> messages, so it
will be much more acceptable if you use some form of credential helper
(e.g. the 'sendemail.smtppass' config option), otherwise you will have
to retype password every time when asked.
Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
Documentation/config.txt | 8 ++++++++
Documentation/git-send-email.txt | 11 +++++++++++
contrib/completion/git-completion.bash | 2 ++
git-send-email.perl | 18 ++++++++++++++++++
4 files changed, 39 insertions(+)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 96e9cf8b7..173ed63f6 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2917,6 +2917,14 @@ sendemail.xmailer::
sendemail.signedoffcc (deprecated)::
Deprecated alias for `sendemail.signedoffbycc`.
+sendemail.smtpbatchsize::
+ Number of messages to be sent per connection, after that a relogin
+ will happen. if the value is 0 or undefined, send all messages in
+ one connection.
+
+sendemail.smtprelogindelay::
+ Seconds wait before reconnecting to smtp server.
+
showbranch.default::
The default set of branches for linkgit:git-show-branch[1].
See linkgit:git-show-branch[1].
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 9d66166f6..5380d8c95 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -248,6 +248,17 @@ must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
+--batch-size=<num>::
+ Some email servers (e.g. smtp.163.com) limit the number emails to be
+ sent per session(connection) and this will lead to a faliure when
+ sending many messages. With this option, send-email will disconnect after
+ sending $<num> messages and wait for a few seconds (see --relogin-delay)
+ and reconnect, to work around such a limit.
+
+--relogin-delay=<int>::
+ Waiting $<int> seconds before reconnecting to smtp server. Used together
+ with --batch-size option.
+
Automating
~~~~~~~~~~
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1ed0a09fe..933e7badf 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2611,6 +2611,8 @@ _git_config ()
sendemail.thread
sendemail.to
sendemail.validate
+ sendemail.smtpbatchsize
+ sendemail.smtprelogindelay
showbranch.default
status.relativePaths
status.showUntrackedFiles
diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..8a1ee0f0d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -81,6 +81,10 @@ git send-email --dump-aliases
This setting forces to use one of the listed mechanisms.
--smtp-debug <0|1> * Disable, enable Net::SMTP debug.
+ --batch-size <int> * send max <int> message per connection.
+ --relogin-delay <int> * delay <int> seconds between two successive login.
+ This option can only be used with --batch-size
+
Automating:
--identity <str> * Use the sendemail.<id> options.
--to-cmd <str> * Email To: via `<str> \$patch_path`
@@ -153,6 +157,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
my $have_mail_address = eval { require Mail::Address; 1 };
my $smtp;
my $auth;
+my $num_sent = 0;
# Regexes for RFC 2047 productions.
my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -216,6 +221,7 @@ my ($cover_cc, $cover_to);
my ($to_cmd, $cc_cmd);
my ($smtp_server, $smtp_server_port, @smtp_server_options);
my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
+my ($batch_size, $relogin_delay);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
my ($validate, $confirm);
my (@suppress_cc);
@@ -247,6 +253,8 @@ my %config_settings = (
"smtppass" => \$smtp_authpass,
"smtpdomain" => \$smtp_domain,
"smtpauth" => \$smtp_auth,
+ "smtpbatchsize" => \$batch_size,
+ "smtprelogindelay" => \$relogin_delay,
"to" => \@initial_to,
"tocmd" => \$to_cmd,
"cc" => \@initial_cc,
@@ -358,6 +366,8 @@ $rc = GetOptions(
"force" => \$force,
"xmailer!" => \$use_xmailer,
"no-xmailer" => sub {$use_xmailer = 0},
+ "batch-size=i" => \$batch_size,
+ "relogin-delay=i" => \$relogin_delay,
);
usage() if $help;
@@ -1664,6 +1674,14 @@ foreach my $t (@files) {
}
}
$message_id = undef;
+ $num_sent++;
+ if (defined $batch_size && $num_sent == $batch_size) {
+ $num_sent = 0;
+ $smtp->quit if defined $smtp;
+ undef $smtp;
+ undef $auth;
+ sleep($relogin_delay) if defined $relogin_delay;
+ }
}
# Execute a command (e.g. $to_cmd) to get a list of email addresses
--
2.13.0.rc2.116.g565bdd0fc.dirty
next reply other threads:[~2017-05-21 13:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-21 12:59 xiaoqiang zhao [this message]
2017-05-22 2:14 ` [PATCH v5] send-email: --batch-size to work around some SMTP server limit Junio C Hamano
2017-05-22 3:19 ` Zhaoxiangqiang
2018-02-07 19:45 ` [PATCH] send-email: have default batch size when relogin delay is given Stefan Beller
2018-02-07 19:50 ` Eric Sunshine
2018-02-07 23:43 ` [PATCH] send-email: error out when relogin delay is missing Stefan Beller
2018-02-08 5:45 ` xiaoqiang zhao
2018-02-08 8:08 ` Eric Sunshine
2018-02-08 18:21 ` Stefan Beller
2018-02-08 22:00 ` Eric Sunshine
2018-02-12 19:44 ` Stefan Beller
2017-05-22 9:26 ` [PATCH v5] send-email: --batch-size to work around some SMTP server limit Ævar Arnfjörð Bjarmason
2017-05-23 7:46 ` Junio C Hamano
2017-05-23 8:30 ` Jan Viktorin
2017-05-23 12:55 ` 赵小强
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170521125950.5524-1-zxq_yx_007@163.com \
--to=zxq_yx_007@163.com \
--cc=artagnon@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mina86@mina86.com \
--cc=mst@kernel.org \
--cc=pbonzini@redhat.com \
--cc=viktorin@rehivetech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).