{"thread":{"id":"10000","subject":"[PATCH] Add ability to specify SMTP server port when using git-send-email.","startedAt":"2007-09-24T20:34:18Z","lastAt":"2007-09-25T06:24:33Z","messageCount":2,"participants":["Glenn Rempe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"53945","messageId":"1190666058-10969-1-git-send-email-glenn@rempe.us","threadId":"10000","inReplyTo":null,"subject":"[PATCH] Add ability to specify SMTP server port when using git-send-email.","fromName":"Glenn Rempe","fromEmail":"glenn@rempe.us","sentAt":"2007-09-24T20:34:18Z","receivedAt":"2007-09-24T20:34:18Z","isPatch":true,"sender":{"key":"glenn@rempe.us","avatar":"https://gravatar.com/avatar/5febe06f1feb5a86bed5aee7b660b18f010bb0b00c48e91af84c2e179e344c50?d=mp&s=160"},"body":"Add ability to specify custom SMTP server port using\nsmtpserverport config value or --smtp-server-port command\nline option.\n\nWill default to port 25 if smtpssl config is set\nto false or --smtp-ssl command line is unset.\n\nWill default to port 465 if smtpssl config is set\nto true or --smtp-ssl is set.\n\nUser can specify any arbitrary port number for standard or\nSSL connections.\n\nUsers should be aware that sending auth info over non-ssl\nconnections may be unsafe.\n\nSigned-off-by: Glenn Rempe <glenn@rempe.us>\n---\n git-send-email.perl |   48 +++++++++++++++++++++++++++++++++++++-----------\n 1 files changed, 37 insertions(+), 11 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 4031e86..7c9c302 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -79,6 +79,10 @@ Options:\n    --smtp-server  If set, specifies the outgoing SMTP server to use.\n                   Defaults to localhost.\n \n+   --smtp-server-port If set, specifies the port on the outgoing SMTP\n+   server to use. Defaults to port 25 unless --smtp-ssl is set in\n+   which case it will default to port 465.\n+\n    --smtp-user    The username for SMTP-AUTH.\n \n    --smtp-pass    The password for SMTP-AUTH.\n@@ -172,7 +176,7 @@ my ($quiet, $dry_run) = (0, 0);\n \n # Variables with corresponding config settings\n my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);\n-my ($smtp_server, $smtp_authuser, $smtp_authpass, $smtp_ssl);\n+my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);\n my ($identity, $aliasfiletype, @alias_files);\n \n my %config_bool_settings = (\n@@ -185,6 +189,7 @@ my %config_bool_settings = (\n \n my %config_settings = (\n     \"smtpserver\" => \\$smtp_server,\n+    \"smtpserverport\" => \\$smtp_server_port,\n     \"smtpuser\" => \\$smtp_authuser,\n     \"smtppass\" => \\$smtp_authpass,\n     \"cccmd\" => \\$cc_cmd,\n@@ -204,6 +209,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n \t\t    \"bcc=s\" => \\@bcclist,\n \t\t    \"chain-reply-to!\" => \\$chain_reply_to,\n \t\t    \"smtp-server=s\" => \\$smtp_server,\n+\t\t    \"smtp-server-port=s\" => \\$smtp_server_port,\n \t\t    \"smtp-user=s\" => \\$smtp_authuser,\n \t\t    \"smtp-pass=s\" => \\$smtp_authpass,\n \t\t    \"smtp-ssl!\" => \\$smtp_ssl,\n@@ -375,6 +381,14 @@ if (!defined $smtp_server) {\n \t$smtp_server ||= 'localhost'; # could be 127.0.0.1, too... *shrug*\n }\n \n+if (!defined $smtp_server_port) {\n+  if ($smtp_ssl) {\n+    $smtp_server_port = 465  # SSL port\n+  } else {\n+    $smtp_server_port = 25  # Non-SSL port\n+  }\n+}\n+\n if ($compose) {\n \t# Note that this does not need to be secure, but we will make a small\n \t# effort to have it be unique\n@@ -604,20 +618,32 @@ X-Mailer: git-send-email $gitversion\n \t} else {\n \t\tif ($smtp_ssl) {\n \t\t\trequire Net::SMTP::SSL;\n-\t\t\t$smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => 465 );\n+\t\t\t$smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => $smtp_server_port );\n \t\t}\n \t\telse {\n \t\t\trequire Net::SMTP;\n-\t\t\t$smtp ||= Net::SMTP->new( $smtp_server );\n+\t\t\t$smtp ||= Net::SMTP->new( $smtp_server . \":\" . $smtp_server_port );\n \t\t}\n-\t\t$smtp->auth( $smtp_authuser, $smtp_authpass )\n-\t\t\tor die $smtp->message if (defined $smtp_authuser);\n-\t\t$smtp->mail( $raw_from ) or die $smtp->message;\n-\t\t$smtp->to( @recipients ) or die $smtp->message;\n-\t\t$smtp->data or die $smtp->message;\n-\t\t$smtp->datasend(\"$header\\n$message\") or die $smtp->message;\n-\t\t$smtp->dataend() or die $smtp->message;\n-\t\t$smtp->ok or die \"Failed to send $subject\\n\".$smtp->message;\n+    \n+    # we'll get an ugly error if $smtp was undefined above.\n+    # If so we'll catch it and present something friendlier.\n+    if ($smtp) {\n+\n+      if ((defined $smtp_authuser) && (defined $smtp_authpass)) {\n+        $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;\n+      }\n+\n+      $smtp->mail( $raw_from ) or die $smtp->message;\n+      $smtp->to( @recipients ) or die $smtp->message;\n+      $smtp->data or die $smtp->message;\n+      $smtp->datasend(\"$header\\n$message\") or die $smtp->message;\n+      $smtp->dataend() or die $smtp->message;\n+      $smtp->ok or die \"Failed to send $subject\\n\".$smtp->message;\n+      \n+    } else {\n+      die \"Unable to initialize SMTP properly.  Is there something wrong with your config?\";\n+    }\n+\n \t}\n \tif ($quiet) {\n \t\tprintf (($dry_run ? \"Dry-\" : \"\").\"Sent %s\\n\", $subject);\n-- \n1.5.3.2.83.gc6869\n"},{"id":"53964","messageId":"7v8x6v6z4u.fsf@gitster.siamese.dyndns.org","threadId":"10000","inReplyTo":"1190666058-10969-1-git-send-email-glenn@rempe.us","subject":"Re: [PATCH] Add ability to specify SMTP server port when using git-send-email.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-25T06:24:33Z","receivedAt":"2007-09-25T06:24:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Glenn Rempe <glenn@rempe.us> writes:\n\n>  git-send-email.perl |   48 +++++++++++++++++++++++++++++++++++++-----------\n>  1 files changed, 37 insertions(+), 11 deletions(-)\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index 4031e86..7c9c302 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -79,6 +79,10 @@ Options:\n>     --smtp-server  If set, specifies the outgoing SMTP server to use.\n>                    Defaults to localhost.\n>  \n> +   --smtp-server-port If set, specifies the port on the outgoing SMTP\n> +   server to use. Defaults to port 25 unless --smtp-ssl is set in\n> +   which case it will default to port 465.\n> +\n\nThis paragraph look inconsistent with different indentation\nfor second and subsequent lines.\n\n> @@ -375,6 +381,14 @@ if (!defined $smtp_server) {\n>  \t$smtp_server ||= 'localhost'; # could be 127.0.0.1, too... *shrug*\n>  }\n>  \n> +if (!defined $smtp_server_port) {\n> +  if ($smtp_ssl) {\n> +    $smtp_server_port = 465  # SSL port\n> +  } else {\n> +    $smtp_server_port = 25  # Non-SSL port\n> +  }\n> +}\n> +\n>  if ($compose) {\n>  \t# Note that this does not need to be secure, but we will make a small\n>  \t# effort to have it be unique\n> @@ -604,20 +618,32 @@ X-Mailer: git-send-email $gitversion\n>  \t} else {\n>  \t\tif ($smtp_ssl) {\n>  \t\t\trequire Net::SMTP::SSL;\n> -\t\t\t$smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => 465 );\n> +\t\t\t$smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => $smtp_server_port );\n>  \t\t}\n>  \t\telse {\n>  \t\t\trequire Net::SMTP;\n> -\t\t\t$smtp ||= Net::SMTP->new( $smtp_server );\n> +\t\t\t$smtp ||= Net::SMTP->new( $smtp_server . \":\" . $smtp_server_port );\n>  \t\t}\n\nThis change suggests that, although undocumented, existing users\ncould have already been using\n\n\t--smtp-server=smtp.myisp.com:26\n\nto specify a nonstandard port, and this patch, while bringing in\nthe support for a nonstandard port as an official feature, would\nbreak such a setup.  I wonder how real the issue is, and if we\ncan work it around easily.  For example,\n\n (1) drop the \"default to 25 for smtp if undefined\" part we saw\n     earlier;\n\n (2) redo this part as\n\n\tif ($smtp_ssl) {\n\t\t... as you have it ...\n\t} else {\n\t\trequire Net::SMTP;\n                $smtp ||= Net::SMTP->new((defined $smtp_server_port) ?\n\t\t\t\t\t \"$smtp_server:$smtp_server_port\" :\n                                         $smtp_server);\n\t}\n\n> -\t\t$smtp->auth( $smtp_authuser, $smtp_authpass )\n> -\t\t\tor die $smtp->message if (defined $smtp_authuser);\n> ...\n> +    \n> +    # we'll get an ugly error if $smtp was undefined above.\n> +    # If so we'll catch it and present something friendlier.\n> +    if ($smtp) {\n> +\n> +      if ((defined $smtp_authuser) && (defined $smtp_authpass)) {\n> +        $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;\n> +      }\n> +    ...\n> +    } else {\n> +      die \"Unable to initialize SMTP properly.  Is there something wrong with your config?\";\n> +    }\n\n\nI'd prefer the check done the opposite order, like\n\n\tif (!$smtp) {\n        \tdie ...\n\t}\n\nwithout an else clause.\n"}]}