summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorxiaoqiang zhao <zxq_yx_007@163.com>2017-05-21 12:59:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-07-05 16:09:45 (GMT)
commit5453b83bdf92efbfe9e9aaa54d4c62ce48ced2f5 (patch)
treedeb99db272d4e17527dce0f7a9b92dc29264bf8c /git-send-email.perl
parentb06d3643105c8758ed019125a4399cb7efdcce2c (diff)
downloadgit-5453b83bdf92efbfe9e9aaa54d4c62ce48ced2f5.zip
git-5453b83bdf92efbfe9e9aaa54d4c62ce48ced2f5.tar.gz
git-5453b83bdf92efbfe9e9aaa54d4c62ce48ced2f5.tar.bz2
send-email: --batch-size to work around some SMTP server limit
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 two configuration variables to give these options the default. Note: We will use this as a band-aid for now, but in the longer term, we should look at and react to the SMTP error code from the server; Xianqiang reports that 450 and 451 are returned by problematic servers. cf. https://public-inbox.org/git/7993e188.d18d.15c3560bcaf.Coremail.zxq_yx_007@163.com/ Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl18
1 files changed, 18 insertions, 0 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a51..8a1ee0f 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