send-email --smtp-server-port: allow overriding the default port
You can use --smtp-server-port option to specify a port different from the default (typically, SMTP servers listen to smtp port 25 and ssmtp port 465). Users should be aware that sending auth info over non-ssl connections may be unsafe or just may not work at all depending on SMTP server config. Signed-off-by: Glenn Rempe <glenn@rempe.us> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5166810b1e
commit
44b2476a12
@ -91,6 +91,11 @@ The --cc option must be repeated for each user you want on the cc list.
|
|||||||
`/usr/lib/sendmail` if such program is available, or
|
`/usr/lib/sendmail` if such program is available, or
|
||||||
`localhost` otherwise.
|
`localhost` otherwise.
|
||||||
|
|
||||||
|
--smtp-server-port::
|
||||||
|
Specifies a port different from the default port (SMTP
|
||||||
|
servers typically listen to smtp port 25 and ssmtp port
|
||||||
|
465).
|
||||||
|
|
||||||
--smtp-user, --smtp-pass::
|
--smtp-user, --smtp-pass::
|
||||||
Username and password for SMTP-AUTH. Defaults are the values of
|
Username and password for SMTP-AUTH. Defaults are the values of
|
||||||
the configuration values 'sendemail.smtpuser' and
|
the configuration values 'sendemail.smtpuser' and
|
||||||
|
@ -77,7 +77,10 @@ Options:
|
|||||||
the default section.
|
the default section.
|
||||||
|
|
||||||
--smtp-server If set, specifies the outgoing SMTP server to use.
|
--smtp-server If set, specifies the outgoing SMTP server to use.
|
||||||
Defaults to localhost.
|
Defaults to localhost. Port number can be specified here with
|
||||||
|
hostname:port format or by using --smtp-server-port option.
|
||||||
|
|
||||||
|
--smtp-server-port Specify a port on the outgoing SMTP server to connect to.
|
||||||
|
|
||||||
--smtp-user The username for SMTP-AUTH.
|
--smtp-user The username for SMTP-AUTH.
|
||||||
|
|
||||||
@ -172,8 +175,8 @@ my ($quiet, $dry_run) = (0, 0);
|
|||||||
|
|
||||||
# Variables with corresponding config settings
|
# Variables with corresponding config settings
|
||||||
my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
|
my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
|
||||||
my ($smtp_server, $smtp_authuser, $smtp_authpass, $smtp_ssl);
|
my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
|
||||||
my ($identity, $aliasfiletype, @alias_files);
|
my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
|
||||||
|
|
||||||
my %config_bool_settings = (
|
my %config_bool_settings = (
|
||||||
"thread" => [\$thread, 1],
|
"thread" => [\$thread, 1],
|
||||||
@ -185,6 +188,7 @@ my %config_bool_settings = (
|
|||||||
|
|
||||||
my %config_settings = (
|
my %config_settings = (
|
||||||
"smtpserver" => \$smtp_server,
|
"smtpserver" => \$smtp_server,
|
||||||
|
"smtpserverport" => \$smtp_server_port,
|
||||||
"smtpuser" => \$smtp_authuser,
|
"smtpuser" => \$smtp_authuser,
|
||||||
"smtppass" => \$smtp_authpass,
|
"smtppass" => \$smtp_authpass,
|
||||||
"cccmd" => \$cc_cmd,
|
"cccmd" => \$cc_cmd,
|
||||||
@ -204,6 +208,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
|
|||||||
"bcc=s" => \@bcclist,
|
"bcc=s" => \@bcclist,
|
||||||
"chain-reply-to!" => \$chain_reply_to,
|
"chain-reply-to!" => \$chain_reply_to,
|
||||||
"smtp-server=s" => \$smtp_server,
|
"smtp-server=s" => \$smtp_server,
|
||||||
|
"smtp-server-port=s" => \$smtp_server_port,
|
||||||
"smtp-user=s" => \$smtp_authuser,
|
"smtp-user=s" => \$smtp_authuser,
|
||||||
"smtp-pass=s" => \$smtp_authpass,
|
"smtp-pass=s" => \$smtp_authpass,
|
||||||
"smtp-ssl!" => \$smtp_ssl,
|
"smtp-ssl!" => \$smtp_ssl,
|
||||||
@ -602,16 +607,30 @@ X-Mailer: git-send-email $gitversion
|
|||||||
print $sm "$header\n$message";
|
print $sm "$header\n$message";
|
||||||
close $sm or die $?;
|
close $sm or die $?;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if (!defined $smtp_server) {
|
||||||
|
die "The required SMTP server is not properly defined."
|
||||||
|
}
|
||||||
|
|
||||||
if ($smtp_ssl) {
|
if ($smtp_ssl) {
|
||||||
|
$smtp_server_port ||= 465; # ssmtp
|
||||||
require Net::SMTP::SSL;
|
require Net::SMTP::SSL;
|
||||||
$smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => 465 );
|
$smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
require Net::SMTP;
|
require Net::SMTP;
|
||||||
$smtp ||= Net::SMTP->new( $smtp_server );
|
$smtp ||= Net::SMTP->new((defined $smtp_server_port)
|
||||||
|
? "$smtp_server:$smtp_server_port"
|
||||||
|
: $smtp_server);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$smtp) {
|
||||||
|
die "Unable to initialize SMTP properly. Is there something wrong with your config?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((defined $smtp_authuser) && (defined $smtp_authpass)) {
|
||||||
|
$smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
|
||||||
}
|
}
|
||||||
$smtp->auth( $smtp_authuser, $smtp_authpass )
|
|
||||||
or die $smtp->message if (defined $smtp_authuser);
|
|
||||||
$smtp->mail( $raw_from ) or die $smtp->message;
|
$smtp->mail( $raw_from ) or die $smtp->message;
|
||||||
$smtp->to( @recipients ) or die $smtp->message;
|
$smtp->to( @recipients ) or die $smtp->message;
|
||||||
$smtp->data or die $smtp->message;
|
$smtp->data or die $smtp->message;
|
||||||
|
Loading…
Reference in New Issue
Block a user