@matheusbsbs / matheus-bagliano / commits / 44b2476a12
Fork 0

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>

Junio C Hamano committed Sep 25, 2007 at 17:27 UTC 44b2476a1278c87d6985993b5e6fd45f1e5f08f2
2 files changed +31 -7
Documentation/git-send-email.txt
+5
@@ -91,6 +91,11 @@ The --cc option must be repeated for each user you want on the cc list.
91 `/usr/lib/sendmail` if such program is available, or
92 `localhost` otherwise.
93
94 +--smtp-server-port::
95 + Specifies a port different from the default port (SMTP
96 + servers typically listen to smtp port 25 and ssmtp port
97 + 465).
98 +
99 --smtp-user, --smtp-pass::
100 Username and password for SMTP-AUTH. Defaults are the values of
101 the configuration values 'sendemail.smtpuser' and
git-send-email.perl
+26 -7
@@ -77,7 +77,10 @@ Options:
77 the default section.
78
79 --smtp-server If set, specifies the outgoing SMTP server to use.
80 - Defaults to localhost.
80 + Defaults to localhost. Port number can be specified here with
81 + hostname:port format or by using --smtp-server-port option.
82 +
83 + --smtp-server-port Specify a port on the outgoing SMTP server to connect to.
84
85 --smtp-user The username for SMTP-AUTH.
86
@@ -172,8 +175,8 @@ my ($quiet, $dry_run) = (0, 0);
175
176 # Variables with corresponding config settings
177 my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
175 -my ($smtp_server, $smtp_authuser, $smtp_authpass, $smtp_ssl);
176 -my ($identity, $aliasfiletype, @alias_files);
178 +my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
179 +my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
180
181 my %config_bool_settings = (
182 "thread" => [\$thread, 1],
@@ -185,6 +188,7 @@ my %config_bool_settings = (
188
189 my %config_settings = (
190 "smtpserver" => \$smtp_server,
191 + "smtpserverport" => \$smtp_server_port,
192 "smtpuser" => \$smtp_authuser,
193 "smtppass" => \$smtp_authpass,
194 "cccmd" => \$cc_cmd,
@@ -204,6 +208,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
208 "bcc=s" => \@bcclist,
209 "chain-reply-to!" => \$chain_reply_to,
210 "smtp-server=s" => \$smtp_server,
211 + "smtp-server-port=s" => \$smtp_server_port,
212 "smtp-user=s" => \$smtp_authuser,
213 "smtp-pass=s" => \$smtp_authpass,
214 "smtp-ssl!" => \$smtp_ssl,
@@ -602,16 +607,30 @@ X-Mailer: git-send-email $gitversion
607 print $sm "$header\n$message";
608 close $sm or die $?;
609 } else {
610 +
611 + if (!defined $smtp_server) {
612 + die "The required SMTP server is not properly defined."
613 + }
614 +
615 if ($smtp_ssl) {
616 + $smtp_server_port ||= 465; # ssmtp
617 require Net::SMTP::SSL;
607 - $smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => 465 );
618 + $smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port);
619 }
620 else {
621 require Net::SMTP;
611 - $smtp ||= Net::SMTP->new( $smtp_server );
622 + $smtp ||= Net::SMTP->new((defined $smtp_server_port)
623 + ? "$smtp_server:$smtp_server_port"
624 + : $smtp_server);
625 + }
626 +
627 + if (!$smtp) {
628 + die "Unable to initialize SMTP properly. Is there something wrong with your config?";
629 + }
630 +
631 + if ((defined $smtp_authuser) && (defined $smtp_authpass)) {
632 + $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
633 }
613 - $smtp->auth( $smtp_authuser, $smtp_authpass )
614 - or die $smtp->message if (defined $smtp_authuser);
634 $smtp->mail( $raw_from ) or die $smtp->message;
635 $smtp->to( @recipients ) or die $smtp->message;
636 $smtp->data or die $smtp->message;