debian/0000755000000000000000000000000012210637440007165 5ustar debian/changelog0000644000000000000000000000711112210637440011037 0ustar sendemail (1.56-5) unstable; urgency=low * Add local-sendmail.patch. Thanks to Olivier Mehani . -- Alejandro Garrido Mota Sun, 01 Sep 2013 15:11:37 +0200 sendemail (1.56-4) unstable; urgency=low * Upload to unstable -- Alejandro Garrido Mota Fri, 23 May 2013 10:10:06 -0430 sendemail (1.56-3) experimental; urgency=low * Add patch to fix fails when tls is enabled (Closes: #679911). * d/control: - Update Standards-Version field to 3.9.4. - Add Vcs-Git and Vcs-Browser field. - Replace debhelper version in B-D - Improve 'Homepage' field. Thanks Feth Arezki (Closes: #703681). * d/copyright: - Update to copyright format 1.0. - Update copyright dates. * Update d/compat file to dh9. -- Alejandro Garrido Mota Thu, 03 Mar 2013 11:00:23 -0430 sendemail (1.56-2) unstable; urgency=low * Remove DH_VERBOSE in d/rules * Add IPV6 support (Closes: #591920) * Update Standards-Version field * Fix d/watch file * Update d/copyright to dep5 * Update debhelper version to '(>= 7.0.50~)' in Build-Depends field * Fix spelling error (s/completly/completely) in d/control * Add d/patches dir * Include IPV6 patch support, thanks Roman Mamedov . * Add libio-socket-inet6-perl in Depends -- Alejandro Garrido Mota Sun, 12 Sep 2010 12:11:17 -0430 sendemail (1.56-1) unstable; urgency=low * New upstream release (Closes: #521894) * Update Standards-Version to 3.8.3 * Add watch file * Implemented dh7 * Rename "docs" file to "sendemail.docs" * Add ${misc:Depends} in Depends field * Add sendemail.links, sendemail.manpages and sendemail.install -- Alejandro Garrido Mota Sun, 3 Oct 2009 14:18:52 -0430 sendemail (1.55-3) unstable; urgency=low * Add symlink '/usr/bin/sendEmail' to '/usr/bin/sendemail' (Closes: #519083) -- Alejandro Garrido Mota Sun, 12 Apr 2009 18:21:43 -0430 sendemail (1.55-2) unstable; urgency=low * Add libio-socket-ssl-perl and libnet-ssleay-perl as Suggests. Since sendEmail v1.54, TLS support is included but not used by default. These perl modules are necessary to use this functionality if specified with the -o tls=yes command line option. Closes: #487687 * Improve: - debian/rules file - copyright file - man page - Changelog file - 'Description' field (debian/control) * Change Standards-Version to 3.8.0 * Support debhelper 7 compatibility * Not include menu -- Alejandro Garrido Mota Sun, 14 Dec 2008 23:00:42 -0430 sendemail (1.55-1) unstable; urgency=low * new upstream version * A new mantainer (Closes: #391413) -- Alejandro Garrido Mota Tue, 19 Dec 2006 23:32:40 -0400 sendemail (1.52-4) unstable; urgency=low * QA upload. * Set maintainer to QA Group; Orphaned: #391413 * Conforms with latest Standards Version 3.7.2 -- Michael Ablassmeier Thu, 19 Oct 2006 10:21:23 +0200 sendemail (1.52-3) unstable; urgency=low * Corrupt MIME message when attaching fixed. - Closes: #339988, thanks to Marco Paganini. -- David Moreno Garza Mon, 28 Nov 2005 21:31:39 -0600 sendemail (1.52-2) unstable; urgency=low * Changed maintainer's address. -- David Moreno Garza Sun, 28 Aug 2005 19:58:48 -0500 sendemail (1.52-1) unstable; urgency=low * Initial Release (Closes: #295288). -- David Moreno Garza Mon, 28 Feb 2005 16:11:57 -0600 debian/sendemail.docs0000644000000000000000000000001412210637440011773 0ustar README TODO debian/source/0000755000000000000000000000000012210637440010465 5ustar debian/source/format0000644000000000000000000000001412210637440011673 0ustar 3.0 (quilt) debian/sendemail.manpages0000644000000000000000000000002312210637440012636 0ustar debian/sendEmail.1 debian/sendemail.install0000644000000000000000000000002212210637440012510 0ustar sendEmail usr/bin debian/sendEmail.10000644000000000000000000000376012210637440011156 0ustar .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.38.2. .TH SendEmail "1" "September 2010" "sendEmail" "User Commands" .SH NAME SendEmail \- Lightweight, command line SMTP email client .SH SYNOPSIS .B SendEmail \fB\-f\fR ADDRESS [options] .SH OPTIONS .TP \fB\-f\fR ADDRESS from (sender) email address .IP * At least one recipient required via \fB\-t\fR, \fB\-cc\fR, or \fB\-bcc\fR * Message body required via \fB\-m\fR, STDIN, or \fB\-o\fR message\-file=FILE .IP Common: .TP \fB\-t\fR ADDRESS [ADDR ...] to email address(es) .TP \fB\-u\fR SUBJECT message subject .TP \fB\-m\fR MESSAGE message body .TP \fB\-s\fR SERVER[:PORT] smtp mail relay, default is localhost:25 .TP \fB\-S\fR [SENDMAIL_PATH] use local sendmail utility (default: /usr/bin/sendmail) instead of network MTA .IP Optional: .TP \fB\-a\fR FILE [FILE ...] file attachment(s) .TP \fB\-cc\fR ADDRESS [ADDR ...] cc email address(es) .TP \fB\-bcc\fR ADDRESS [ADDR ...] bcc email address(es) .IP Paranormal: .TP \fB\-xu\fR USERNAME authentication user (for SMTP authentication) .TP \fB\-xp\fR PASSWORD authentication password (for SMTP authentication) .TP \fB\-l\fR LOGFILE log to the specified file .TP \fB\-v\fR verbosity, use multiple times for greater effect .TP \fB\-q\fR be quiet (no stdout output) .TP \fB\-o\fR NAME=VALUE see extended help topic "misc" for details .IP Help: .TP \fB\-\-help\fR TOPIC The following extended help topics are available: .TP addressing explain addressing and related options .TP message explain message body input and related options .TP misc explain \fB\-xu\fR, \fB\-xp\fR, and others .TP networking explain \fB\-s\fR, etc .TP output explain logging and other output options .SH "REPORTING BUGS" Report bugs to .SH AUTHOR sendemail was written by Brandon Zehm . .PP This manual page was written by Brandon Zehm and improved by Alejandro Garrido Mota , for the Debian project (and may be used by others). debian/rules0000755000000000000000000000003712210637440010245 0ustar #!/usr/bin/make -f %: dh $@ debian/patches/0000755000000000000000000000000012210637440010614 5ustar debian/patches/series0000644000000000000000000000010212210637440012022 0ustar fix_ssl_version.patch add-ipv6-support.patch local-sendmail.patch debian/patches/fix_ssl_version.patch0000644000000000000000000000133612210637440015054 0ustar Description: Fix ssl enabled bug. Bug-Debian: http://bugs.debian.org/679911 Author: Alejandro Garrido Mota --- a/sendEmail +++ b/sendEmail @@ -1903,7 +1903,7 @@ if ($conf{'tls_server'} == 1 and $conf{'tls_client'} == 1 and $opt{'tls'} =~ /^(yes|auto)$/) { printmsg("DEBUG => Starting TLS", 2); if (SMTPchat('STARTTLS')) { quit($conf{'error'}, 1); } - if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) { + if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv23:!SSLv2')) { quit("ERROR => TLS setup failed: " . IO::Socket::SSL::errstr(), 1); } printmsg("DEBUG => TLS: Using cipher: ". $SERVER->get_cipher(), 3); debian/patches/local-sendmail.patch0000644000000000000000000007205412210637440014531 0ustar Description: Add support for the use of a local sendmail binary If the -S option is specified (with an optional argument being the path to the sendmail binary to use), sendEmail delegates the SMTP dance to the locate MTA, and simply generates the message and passes it on to the sendmail utility (-bm -t). . This is particularly useful when no actual sendmail runs on the machine, but the email-sending logic is centralised around something like sSMTP which masquerades as a normal sendmail binary. Author: Olivier Mehani --- a/sendEmail +++ b/sendEmail @@ -68,6 +68,10 @@ "tls_client" => 0, ## If TLS is supported by the client (us) "tls_server" => 0, ## If TLS is supported by the remote SMTP server + ## Sendmail + "sendmail" => '/usr/bin/sendmail', + "use_sendmail" => 0, + ## Email "delimiter" => "----MIME delimiter for sendEmail-" ## MIME Delimiter . rand(1000000), ## Add some randomness to the delimiter @@ -102,6 +106,8 @@ ## More variables used later in the program my $SERVER; my $CRLF = "\015\012"; +my $LF = "\012"; +my $LTERM = $CRLF; my $subject = ''; my $header = ''; my $message = ''; @@ -316,6 +322,7 @@ ## Replace '\n' with $CRLF. ## This allows newlines with messages sent on the command line + ## XXX: This might cause problems with use_sendmail=1 $message =~ s/\\n/$CRLF/g; } @@ -340,6 +347,17 @@ else { printmsg("WARNING - The argument after -s was not the server!", 0); $counter--; } } + elsif ($ARGS[$counter] =~ /^-S$/) { ## Sendmail ## + $counter++; + $conf{'use_sendmail'} = 1; + $LTERM = $LF; + if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) { + $conf{'sendmail'} = $ARGS[$counter]; + } else { + $counter--; + } + } + elsif ($ARGS[$counter] =~ /^-b$/) { ## Bind Address ## $counter++; if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) { @@ -420,6 +438,9 @@ if (!$conf{'server'}) { $conf{'server'} = 'localhost'; } if (!$conf{'port'}) { $conf{'port'} = 25; } + if ($conf{'use_sendmail'} && !$conf{'sendmail'}) { + $conf{'sendmail'} = "/usr/bin/sendmail"; + } if (!$from) { quit("ERROR => You must specify a 'from' field! Try --help.", 1); } @@ -451,28 +472,31 @@ quit("ERROR => You used -l to enable logging but didn't specify a log file!", 1); } - if ( $opt{'username'} ) { - if (!$opt{'password'}) { - ## Prompt for a password since one wasn't specified with the -xp option. - $SIG{'ALRM'} = sub { quit("ERROR => Timeout waiting for password inpupt", 1); }; - alarm(60) if ($^O !~ /win/i); ## alarm() doesn't work in win32 - print "Password: "; - $opt{'password'} = ; chomp $opt{'password'}; + ## Check network parameters if needed + if ( !$conf{'use_sendmail'} ) { + if ( $opt{'username'} ) { if (!$opt{'password'}) { - quit("ERROR => A username for SMTP authentication was specified, but no password!", 1); + ## Prompt for a password since one wasn't specified with the -xp option. + $SIG{'ALRM'} = sub { quit("ERROR => Timeout waiting for password inpupt", 1); }; + alarm(60) if ($^O !~ /win/i); ## alarm() doesn't work in win32 + print "Password: "; + $opt{'password'} = ; chomp $opt{'password'}; + if (!$opt{'password'}) { + quit("ERROR => A username for SMTP authentication was specified, but no password!", 1); + } } } - } - - ## Validate the TLS setting - $opt{'tls'} = lc($opt{'tls'}); - if ($opt{'tls'} !~ /^(auto|yes|no)$/) { - quit("ERROR => Invalid TLS setting ($opt{'tls'}). Must be one of auto, yes, or no.", 1); - } - - ## If TLS is set to "yes", make sure sendEmail loaded the libraries needed. - if ($opt{'tls'} eq 'yes' and $conf{'tls_client'} == 0) { - quit("ERROR => No TLS support! SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)", 1); + + ## Validate the TLS setting + $opt{'tls'} = lc($opt{'tls'}); + if ($opt{'tls'} !~ /^(auto|yes|no)$/) { + quit("ERROR => Invalid TLS setting ($opt{'tls'}). Must be one of auto, yes, or no.", 1); + } + + ## If TLS is set to "yes", make sure sendEmail loaded the libraries needed. + if ($opt{'tls'} eq 'yes' and $conf{'tls_client'} == 0) { + quit("ERROR => No TLS support! SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)", 1); + } } ## Return 0 errors @@ -803,7 +827,6 @@ my $chunk = $_[1]; my $tmp = ''; my $base64 = ''; - my $CRLF = "\r\n"; ################################### ## Convert binary data to base64 ## @@ -833,15 +856,15 @@ $data = ''; $base64 =~ s/.{$padding}$/'=' x $padding/e if $padding; ## Fix the end padding if flag (from above) is set if ($chunk) { - while ($base64 =~ s/(.{1,76})//s) { ## Put $CRLF after each 76 characters - $data .= "$1$CRLF"; + while ($base64 =~ s/(.{1,76})//s) { ## Put $LTERM after each 76 characters + $data .= "$1$LTERM"; } } else { $data = $base64; } - ## Remove any trailing CRLF's + ## Remove any trailing LTERM's $data =~ s/(\r|\n)*$//s; return($data); } @@ -921,12 +944,12 @@ ## Generate and print MIME headers ## ##################################### - $y = "$CRLF--$conf{'delimiter'}$CRLF"; - $y .= "Content-Type: $content_type;$CRLF"; - $y .= " name=\"$filename_name\"$CRLF"; - $y .= "Content-Transfer-Encoding: base64$CRLF"; - $y .= "Content-Disposition: attachment; filename=\"$filename_name\"$CRLF"; - $y .= "$CRLF"; + $y = "$LTERM--$conf{'delimiter'}$LTERM"; + $y .= "Content-Type: $content_type;$LTERM"; + $y .= " name=\"$filename_name\"$LTERM"; + $y .= "Content-Transfer-Encoding: base64$LTERM"; + $y .= "Content-Disposition: attachment; filename=\"$filename_name\"$LTERM"; + $y .= "$LTERM"; print $SERVER $y; @@ -960,7 +983,7 @@ ## Print chunks to the server ## ################################ while ($base64 =~ s/(.{76})//s) { - print $SERVER "$1$CRLF"; + print $SERVER "$1$LTERM"; } } @@ -983,7 +1006,7 @@ $res =~ s/.{$padding}$/'=' x $padding/e if $padding; ## Fix the end padding if flag (from above) is set if ($res) { while ($res =~ s/(.{1,76})//s) { ## Send it to the email server. - print $SERVER "$1$CRLF"; + print $SERVER "$1$LTERM"; } } @@ -1294,6 +1317,7 @@ -u SUBJECT message subject -m MESSAGE message body -s SERVER[:PORT] smtp mail relay, default is $conf{'server'}:$conf{'port'} + -S [SENDMAIL_PATH] use local sendmail utility (default: $conf{'sendmail'}) instead of network MTA ${colorGreen}Optional:${colorNormal} -a FILE [FILE ...] file attachment(s) @@ -1813,14 +1837,14 @@ } } -## Replace bare LF's with CRLF's (\012 should always have \015 with it) -$message =~ s/(\015)?(\012|$)/\015\012/g; +## Replace bare LF's with LTERM's (\012 should always have \015 with it) +$message =~ s/(\015)?(\012|$)/$LTERM/g; -## Replace bare CR's with CRLF's (\015 should always have \012 with it) -$message =~ s/(\015)(\012|$)?/\015\012/g; +## Replace bare CR's with LTERM's (\015 should always have \012 with it) +$message =~ s/(\015)(\012|$)?/$LTERM/g; ## Check message for bare periods and encode them -$message =~ s/(^|$CRLF)(\.{1})($CRLF|$)/$1.$2$3/g; +$message =~ s/(^|$LTERM)(\.{1})($LTERM|$)/$1.$2$3/g; ## Get the current date for the email header my ($sec,$min,$hour,$mday,$mon,$year,$day) = gmtime(); @@ -1828,181 +1852,184 @@ my $date = sprintf("%s, %s %s %d %.2d:%.2d:%.2d %s",$day, $mday, $mon, $year, $hour, $min, $sec, $conf{'timezone'}); +if( $conf{'use_sendmail'} ) { + open ($SERVER, "| $conf{'sendmail'} -bm -t") + || die "ERROR => Can't run $conf{'sendmail'}: $!"; +} else { + ################################## + ## Connect to the SMTP server ## + ################################## + printmsg("DEBUG => Connecting to $conf{'server'}:$conf{'port'}", 1); + $SIG{'ALRM'} = sub { + printmsg("ERROR => Timeout while connecting to $conf{'server'}:$conf{'port'} There was no response after $conf{'alarm'} seconds.", 0); + printmsg("HINT => Try specifying a different mail relay with the -s option.", 1); + quit("", 1); + }; + alarm($conf{'alarm'}) if ($^O !~ /win/i); ## alarm() doesn't work in win32; + $SERVER = IO::Socket::INET6->new( PeerAddr => $conf{'server'}, + PeerPort => $conf{'port'}, + LocalAddr => $conf{'bindaddr'}, + Proto => 'tcp', + Autoflush => 1, + timeout => $conf{'alarm'}, + ); + alarm(0) if ($^O !~ /win/i); ## alarm() doesn't work in win32; + ## Make sure we got connected + if ( (!$SERVER) or (!$SERVER->opened()) ) { + printmsg("ERROR => Connection attempt to $conf{'server'}:$conf{'port'} failed: $@", 0); + printmsg("HINT => Try specifying a different mail relay with the -s option.", 1); + quit("", 1); + } -################################## -## Connect to the SMTP server ## -################################## -printmsg("DEBUG => Connecting to $conf{'server'}:$conf{'port'}", 1); -$SIG{'ALRM'} = sub { - printmsg("ERROR => Timeout while connecting to $conf{'server'}:$conf{'port'} There was no response after $conf{'alarm'} seconds.", 0); - printmsg("HINT => Try specifying a different mail relay with the -s option.", 1); - quit("", 1); -}; -alarm($conf{'alarm'}) if ($^O !~ /win/i); ## alarm() doesn't work in win32; -$SERVER = IO::Socket::INET6->new( PeerAddr => $conf{'server'}, - PeerPort => $conf{'port'}, - LocalAddr => $conf{'bindaddr'}, - Proto => 'tcp', - Autoflush => 1, - timeout => $conf{'alarm'}, -); -alarm(0) if ($^O !~ /win/i); ## alarm() doesn't work in win32; - -## Make sure we got connected -if ( (!$SERVER) or (!$SERVER->opened()) ) { - printmsg("ERROR => Connection attempt to $conf{'server'}:$conf{'port'} failed: $@", 0); - printmsg("HINT => Try specifying a different mail relay with the -s option.", 1); - quit("", 1); -} - -## Save our IP address for later -$conf{'ip'} = $SERVER->sockhost(); -printmsg("DEBUG => My IP address is: $conf{'ip'}", 1); - + ## Save our IP address for later + $conf{'ip'} = $SERVER->sockhost(); + printmsg("DEBUG => My IP address is: $conf{'ip'}", 1); -######################### -## Do the SMTP Dance ## -######################### -## Read initial greeting to make sure we're talking to a live SMTP server -if (SMTPchat()) { quit($conf{'error'}, 1); } + ######################### + ## Do the SMTP Dance ## + ######################### -## We're about to use $opt{'fqdn'}, make sure it isn't empty -if (!$opt{'fqdn'}) { - ## Ok, that means we couldn't get a hostname, how about using the IP address for the HELO instead - $opt{'fqdn'} = "[" . $conf{'ip'} . "]"; -} + ## Read initial greeting to make sure we're talking to a live SMTP server + if (SMTPchat()) { quit($conf{'error'}, 1); } -## EHLO -if (SMTPchat('EHLO ' . $opt{'fqdn'})) { - printmsg($conf{'error'}, 0); - printmsg("NOTICE => EHLO command failed, attempting HELO instead"); - if (SMTPchat('HELO ' . $opt{'fqdn'})) { quit($conf{'error'}, 1); } - if ( $opt{'username'} and $opt{'password'} ) { - printmsg("WARNING => The mail server does not support SMTP authentication!", 0); + ## We're about to use $opt{'fqdn'}, make sure it isn't empty + if (!$opt{'fqdn'}) { + ## Ok, that means we couldn't get a hostname, how about using the IP address for the HELO instead + $opt{'fqdn'} = "[" . $conf{'ip'} . "]"; } -} -else { - - ## Determin if the server supports TLS - if ($conf{'SMTPchat_response'} =~ /STARTTLS/) { - $conf{'tls_server'} = 1; - printmsg("DEBUG => The remote SMTP server supports TLS :)", 2); + + ## EHLO + if (SMTPchat('EHLO ' . $opt{'fqdn'})) { + printmsg($conf{'error'}, 0); + printmsg("NOTICE => EHLO command failed, attempting HELO instead"); + if (SMTPchat('HELO ' . $opt{'fqdn'})) { quit($conf{'error'}, 1); } + if ( $opt{'username'} and $opt{'password'} ) { + printmsg("WARNING => The mail server does not support SMTP authentication!", 0); + } } else { - $conf{'tls_server'} = 0; - printmsg("DEBUG => The remote SMTP server does NOT support TLS :(", 2); - } - - ## Start TLS if possible - if ($conf{'tls_server'} == 1 and $conf{'tls_client'} == 1 and $opt{'tls'} =~ /^(yes|auto)$/) { - printmsg("DEBUG => Starting TLS", 2); - if (SMTPchat('STARTTLS')) { quit($conf{'error'}, 1); } - if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv23:!SSLv2')) { - quit("ERROR => TLS setup failed: " . IO::Socket::SSL::errstr(), 1); - } - printmsg("DEBUG => TLS: Using cipher: ". $SERVER->get_cipher(), 3); - printmsg("DEBUG => TLS session initialized :)", 1); - ## Restart our SMTP session - if (SMTPchat('EHLO ' . $opt{'fqdn'})) { quit($conf{'error'}, 1); } - } - elsif ($opt{'tls'} eq 'yes' and $conf{'tls_server'} == 0) { - quit("ERROR => TLS not possible! Remote SMTP server, $conf{'server'}, does not support it.", 1); - } - - - ## Do SMTP Auth if required - if ( $opt{'username'} and $opt{'password'} ) { - if ($conf{'SMTPchat_response'} !~ /AUTH\s/) { - printmsg("NOTICE => Authentication not supported by the remote SMTP server!", 0); + ## Determine if the server supports TLS + if ($conf{'SMTPchat_response'} =~ /STARTTLS/) { + $conf{'tls_server'} = 1; + printmsg("DEBUG => The remote SMTP server supports TLS :)", 2); } else { - my $auth_succeeded = 0; - my $mutual_method = 0; - - # ## SASL CRAM-MD5 authentication method - # if ($conf{'SMTPchat_response'} =~ /\bCRAM-MD5\b/i) { - # printmsg("DEBUG => SMTP-AUTH: Using CRAM-MD5 authentication method", 1); - # if (SMTPchat('AUTH CRAM-MD5')) { quit($conf{'error'}, 1); } - # - # ## FIXME!! - # - # printmsg("DEBUG => User authentication was successful", 1); - # } + $conf{'tls_server'} = 0; + printmsg("DEBUG => The remote SMTP server does NOT support TLS :(", 2); + } + + ## Start TLS if possible + if ($conf{'tls_server'} == 1 and $conf{'tls_client'} == 1 and $opt{'tls'} =~ /^(yes|auto)$/) { + printmsg("DEBUG => Starting TLS", 2); + if (SMTPchat('STARTTLS')) { quit($conf{'error'}, 1); } + if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv23:!SSLv2')) { + quit("ERROR => TLS setup failed: " . IO::Socket::SSL::errstr(), 1); + } + printmsg("DEBUG => TLS: Using cipher: ". $SERVER->get_cipher(), 3); + printmsg("DEBUG => TLS session initialized :)", 1); - ## SASL LOGIN authentication method - if ($auth_succeeded == 0 and $conf{'SMTPchat_response'} =~ /\bLOGIN\b/i) { - $mutual_method = 1; - printmsg("DEBUG => SMTP-AUTH: Using LOGIN authentication method", 1); - if (!SMTPchat('AUTH LOGIN')) { - if (!SMTPchat(base64_encode($opt{'username'}))) { - if (!SMTPchat(base64_encode($opt{'password'}))) { - $auth_succeeded = 1; - printmsg("DEBUG => User authentication was successful (Method: LOGIN)", 1); + ## Restart our SMTP session + if (SMTPchat('EHLO ' . $opt{'fqdn'})) { quit($conf{'error'}, 1); } + } + elsif ($opt{'tls'} eq 'yes' and $conf{'tls_server'} == 0) { + quit("ERROR => TLS not possible! Remote SMTP server, $conf{'server'}, does not support it.", 1); + } + + + ## Do SMTP Auth if required + if ( $opt{'username'} and $opt{'password'} ) { + if ($conf{'SMTPchat_response'} !~ /AUTH\s/) { + printmsg("NOTICE => Authentication not supported by the remote SMTP server!", 0); + } + else { + my $auth_succeeded = 0; + my $mutual_method = 0; + + # ## SASL CRAM-MD5 authentication method + # if ($conf{'SMTPchat_response'} =~ /\bCRAM-MD5\b/i) { + # printmsg("DEBUG => SMTP-AUTH: Using CRAM-MD5 authentication method", 1); + # if (SMTPchat('AUTH CRAM-MD5')) { quit($conf{'error'}, 1); } + # + # ## FIXME!! + # + # printmsg("DEBUG => User authentication was successful", 1); + # } + + ## SASL LOGIN authentication method + if ($auth_succeeded == 0 and $conf{'SMTPchat_response'} =~ /\bLOGIN\b/i) { + $mutual_method = 1; + printmsg("DEBUG => SMTP-AUTH: Using LOGIN authentication method", 1); + if (!SMTPchat('AUTH LOGIN')) { + if (!SMTPchat(base64_encode($opt{'username'}))) { + if (!SMTPchat(base64_encode($opt{'password'}))) { + $auth_succeeded = 1; + printmsg("DEBUG => User authentication was successful (Method: LOGIN)", 1); + } } } + if ($auth_succeeded == 0) { + printmsg("DEBUG => SMTP-AUTH: LOGIN authenticaion failed.", 1); + } } - if ($auth_succeeded == 0) { - printmsg("DEBUG => SMTP-AUTH: LOGIN authenticaion failed.", 1); + + ## SASL PLAIN authentication method + if ($auth_succeeded == 0 and $conf{'SMTPchat_response'} =~ /\bPLAIN\b/i) { + $mutual_method = 1; + printmsg("DEBUG => SMTP-AUTH: Using PLAIN authentication method", 1); + if (SMTPchat('AUTH PLAIN ' . base64_encode("$opt{'username'}\0$opt{'username'}\0$opt{'password'}"))) { + printmsg("DEBUG => SMTP-AUTH: PLAIN authenticaion failed.", 1); + } + else { + $auth_succeeded = 1; + printmsg("DEBUG => User authentication was successful (Method: PLAIN)", 1); + } } - } - - ## SASL PLAIN authentication method - if ($auth_succeeded == 0 and $conf{'SMTPchat_response'} =~ /\bPLAIN\b/i) { - $mutual_method = 1; - printmsg("DEBUG => SMTP-AUTH: Using PLAIN authentication method", 1); - if (SMTPchat('AUTH PLAIN ' . base64_encode("$opt{'username'}\0$opt{'username'}\0$opt{'password'}"))) { - printmsg("DEBUG => SMTP-AUTH: PLAIN authenticaion failed.", 1); + + ## If none of the authentication methods supported by sendEmail were supported by the server, let the user know + if ($mutual_method == 0) { + printmsg("WARNING => SMTP-AUTH: No mutually supported authentication methods available", 0); } - else { - $auth_succeeded = 1; - printmsg("DEBUG => User authentication was successful (Method: PLAIN)", 1); + + ## If we didn't get authenticated, log an error message and exit + if ($auth_succeeded == 0) { + quit("ERROR => ERROR => SMTP-AUTH: Authentication to $conf{'server'}:$conf{'port'} failed.", 1); } } - - ## If none of the authentication methods supported by sendEmail were supported by the server, let the user know - if ($mutual_method == 0) { - printmsg("WARNING => SMTP-AUTH: No mutually supported authentication methods available", 0); - } - - ## If we didn't get authenticated, log an error message and exit - if ($auth_succeeded == 0) { - quit("ERROR => ERROR => SMTP-AUTH: Authentication to $conf{'server'}:$conf{'port'} failed.", 1); - } } } -} -## MAIL FROM -if (SMTPchat('MAIL FROM:<' .(returnAddressParts($from))[1]. '>')) { quit($conf{'error'}, 1); } + ## MAIL FROM + if (SMTPchat('MAIL FROM:<' .(returnAddressParts($from))[1]. '>')) { quit($conf{'error'}, 1); } -## RCPT TO -my $oneRcptAccepted = 0; -foreach my $rcpt (@to, @cc, @bcc) { - my ($name, $address) = returnAddressParts($rcpt); - if (SMTPchat('RCPT TO:<' . $address . '>')) { - printmsg("WARNING => The recipient <$address> was rejected by the mail server, error follows:", 0); - $conf{'error'} =~ s/^ERROR/WARNING/o; - printmsg($conf{'error'}, 0); + ## RCPT TO + my $oneRcptAccepted = 0; + foreach my $rcpt (@to, @cc, @bcc) { + my ($name, $address) = returnAddressParts($rcpt); + if (SMTPchat('RCPT TO:<' . $address . '>')) { + printmsg("WARNING => The recipient <$address> was rejected by the mail server, error follows:", 0); + $conf{'error'} =~ s/^ERROR/WARNING/o; + printmsg($conf{'error'}, 0); + } + elsif ($oneRcptAccepted == 0) { + $oneRcptAccepted = 1; + } } - elsif ($oneRcptAccepted == 0) { - $oneRcptAccepted = 1; + ## If no recipients were accepted we need to exit with an error. + if ($oneRcptAccepted == 0) { + quit("ERROR => Exiting. No recipients were accepted for delivery by the mail server.", 1); } -} -## If no recipients were accepted we need to exit with an error. -if ($oneRcptAccepted == 0) { - quit("ERROR => Exiting. No recipients were accepted for delivery by the mail server.", 1); -} -## DATA -if (SMTPchat('DATA')) { quit($conf{'error'}, 1); } + ## DATA + if (SMTPchat('DATA')) { quit($conf{'error'}, 1); } +} ############################### @@ -2020,19 +2047,19 @@ ## Message-ID: if ($opt{'message-header'} !~ /^Message-ID:/iom) { - $header .= 'Message-ID: <' . $conf{'Message-ID'} . '@' . $conf{'hostname'} . '>' . $CRLF; + $header .= 'Message-ID: <' . $conf{'Message-ID'} . '@' . $conf{'hostname'} . '>' . $LTERM; } ## From: "Name" (the pointless test below is just to keep scoping correct) if ($from and $opt{'message-header'} !~ /^From:/iom) { my ($name, $address) = returnAddressParts($from); - $header .= 'From: "' . $name . '" <' . $address . '>' . $CRLF; + $header .= 'From: "' . $name . '" <' . $address . '>' . $LTERM; } ## Reply-To: if ($opt{'reply-to'} and $opt{'message-header'} !~ /^Reply-To:/iom) { my ($name, $address) = returnAddressParts($opt{'reply-to'}); - $header .= 'Reply-To: "' . $name . '" <' . $address . '>' . $CRLF; + $header .= 'Reply-To: "' . $name . '" <' . $address . '>' . $LTERM; } ## To: "Name" @@ -2052,12 +2079,12 @@ $msg .= ","; } - $header .= $msg . $CRLF; + $header .= $msg . $LTERM; } } ## We always want a To: line so if the only recipients were bcc'd they don't see who it was sent to else { - $header .= "To: \"Undisclosed Recipients\" <>$CRLF"; + $header .= "To: \"Undisclosed Recipients\" <>$LTERM"; } if (scalar(@cc) > 0 and $opt{'message-header'} !~ /^Cc:/iom) { @@ -2073,32 +2100,32 @@ $msg .= ","; } - $header .= $msg . $CRLF; + $header .= $msg . $LTERM; } } if ($opt{'message-header'} !~ /^Subject:/iom) { - $header .= 'Subject: ' . $subject . $CRLF; ## Subject + $header .= 'Subject: ' . $subject . $LTERM; ## Subject } if ($opt{'message-header'} !~ /^Date:/iom) { - $header .= 'Date: ' . $date . $CRLF; ## Date + $header .= 'Date: ' . $date . $LTERM; ## Date } if ($opt{'message-header'} !~ /^X-Mailer:/iom) { - $header .= 'X-Mailer: sendEmail-'.$conf{'version'}.$CRLF; ## X-Mailer + $header .= 'X-Mailer: sendEmail-'.$conf{'version'}.$LTERM; ## X-Mailer } ## I wonder if I should put this in by default? # if ($opt{'message-header'} !~ /^X-Originating-IP:/iom) { - # $header .= 'X-Originating-IP: ['.$conf{'ip'}.']'.$CRLF; ## X-Originating-IP + # $header .= 'X-Originating-IP: ['.$conf{'ip'}.']'.$LTERM; ## X-Originating-IP # } ## Encode all messages with MIME. if ($opt{'message-header'} !~ /^MIME-Version:/iom) { - $header .= "MIME-Version: 1.0$CRLF"; + $header .= "MIME-Version: 1.0$LTERM"; } if ($opt{'message-header'} !~ /^Content-Type:/iom) { my $content_type = 'multipart/mixed'; if (scalar(@attachments) == 0) { $content_type = 'multipart/related'; } - $header .= "Content-Type: $content_type; boundary=\"$conf{'delimiter'}\"$CRLF"; + $header .= "Content-Type: $content_type; boundary=\"$conf{'delimiter'}\"$LTERM"; } ## Send additional message header line(s) if specified @@ -2107,34 +2134,34 @@ } ## Send the message header to the server - print $SERVER $header . $CRLF; + print $SERVER $header . $LTERM; ## Start sending the message body to the server - print $SERVER "This is a multi-part message in MIME format. To properly display this message you need a MIME-Version 1.0 compliant Email program.$CRLF"; - print $SERVER "$CRLF"; + print $SERVER "This is a multi-part message in MIME format. To properly display this message you need a MIME-Version 1.0 compliant Email program.$LTERM"; + print $SERVER "$LTERM"; ## Send message body - print $SERVER "--$conf{'delimiter'}$CRLF"; + print $SERVER "--$conf{'delimiter'}$LTERM"; ## Send a message content-type header: ## If the message contains HTML... if ($opt{'message-content-type'} eq 'html' or ($opt{'message-content-type'} eq 'auto' and $message =~ /^\s*( --- a/sendEmail +++ b/sendEmail @@ -37,6 +37,7 @@ ############################################################################## use strict; use IO::Socket; +use IO::Socket::INET6; ######################## @@ -1839,7 +1840,7 @@ quit("", 1); }; alarm($conf{'alarm'}) if ($^O !~ /win/i); ## alarm() doesn't work in win32; -$SERVER = IO::Socket::INET->new( PeerAddr => $conf{'server'}, +$SERVER = IO::Socket::INET6->new( PeerAddr => $conf{'server'}, PeerPort => $conf{'port'}, LocalAddr => $conf{'bindaddr'}, Proto => 'tcp', debian/sendemail.links0000644000000000000000000000015012210637440012164 0ustar usr/bin/sendEmail usr/bin/sendemail usr/share/man/man1/sendEmail.1.gz usr/share/man/man1/sendemail.1.gz debian/watch0000644000000000000000000000012612210637440010215 0ustar version=3 http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v(.*)\.tar\.gz debian/compat0000644000000000000000000000000212210637440010363 0ustar 9 debian/copyright0000644000000000000000000000166612210637440011131 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Contact: Brandon Zehm Source: http://caspian.dotconf.net/menu/Software/SendEmail/ Upstream-Name: sendemail Files: * Copyright: 2000, Brandon Zehm License: GPL-2+ X-Comment: Per the Berne Convention, the author is assumed to be the copyright holder. Years of copyright are deduced from the CHANGELOG file. Files: debian/* Copyright: 2009-2013, Alejandro Garrido Mota License: GPL-2+ License: GPL-2+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. On Debian systems, the complete text of the GNU General Public License version 3 can be found in `/usr/share/common-licenses/GPL-2'. debian/control0000644000000000000000000000160712210637440010574 0ustar Source: sendemail Section: mail Priority: optional Maintainer: Alejandro Garrido Mota Build-Depends: debhelper (>= 9) Standards-Version: 3.9.4 Homepage: http://www.caspian.dotconf.net/menu/Software/SendEmail/ Vcs-Git: git://github.com/mogaal/sendemail.git Vcs-Browser: https://github.com/mogaal/sendemail Package: sendemail Architecture: all Depends: ${misc:Depends}, ${perl:Depends}, libio-socket-inet6-perl Suggests: libio-socket-ssl-perl, libnet-ssleay-perl Description: lightweight, command line SMTP email client SendEmail is a lightweight, completely command line based, SMTP email agent. It was designed to be used in bash scripts, Perl programs, and web sites, but it is also quite useful in many other contexts. . SendEmail is written in Perl and is unique in that it requires no special modules. It has a straight forward interface, making it very easy to use.