Page Index Toggle Pages: 1 Print
Net::SMTP::TLS (Read 3856 times)
Captain John
Ex Member


Net::SMTP::TLS
Oct 30th, 2008 at 3:23am
Print Post  
a YaBB installation that needed to use smtp.gmail.com as its SMTP server. smtp.gmail.com requires TLS, and I made a relatively small change to YaBB to support TLS using Net::SMTP::TLS (available from CPAN).  Here are the diffs:

diff -u AdminEdit.pl~ AdminEdit.pl
--- AdminEdit.pl~       2005-11-28 19:59:39.000000000 -0800
+++ AdminEdit.pl        2006-11-20 11:15:00.000000000 -0800
@@ -448,7 +448,7 @@
Code
Select All
	 my ($mainchecked, $pflashchecked, $guestaccchecked, $forcechecked, $blankchecked, $agreechecked, $regdischecked, $mailpasschecked, $newpasschecked, $welchecked);
	 my ($menuchecked, $ubbcchecked, $eclickchecked, $aluchecked, $dstchecked, $pbchecked, $insertchecked, $newschecked, $gpchecked, $notifchecked);
	 my ($ahmchecked, $slmchecked, $srbarchecked, $smbarchecked, $smodchecked, $supicchecked, $sutextchecked, $stviewchecked, $strepchecked, $sgichecked);
-	 my ($snfchecked, $fls1, $fls2, $fls3, $truncchecked, $mts1, $mts2, $mts3, $tsl6, $tsl5, $tsl4, $tsl3, $tsl2, $tsl1);
+	 my ($snfchecked, $fls1, $fls2, $fls3, $truncchecked, $mts1, $mts2, $mts3, $mts4, $tsl6, $tsl5, $tsl4, $tsl3, $tsl2, $tsl1);
	 my ($gzc1, $gzc2, $gzc3, $gzchecked, $preregchecked, $bmd1, $bmd2, $defml1, $defml2, $defml3, $defml4);

	 # figure out what to print
@@ -503,6 +503,7 @@
	 if    ($mailtype == 0)     { $mts1 = ' selected="selected" '; }
	 elsif ($mailtype == 1)     { $mts2 = ' selected="selected" '; }
	 elsif ($mailtype == 2)     { $mts3 = ' selected="selected" '; }
+	  elsif ($mailtype == 3)     { $mts4 = ' selected="selected" '; }
	 if    ($timeselected == 6) { $tsl6 = " selected=\"selected\" " }
	 elsif ($timeselected == 5) { $tsl5 = " selected=\"selected\" " }
	 elsif ($timeselected == 4) { $tsl4 = " selected=\"selected\" " }
@@ -892,6 +893,7 @@
			     <option value="0"$mts1>$smtp_txt{'sendmail'}</option>
			     <option value="1"$mts2>$smtp_txt{'smtp'}</option>
			     <option value="2"$mts3>$smtp_txt{'net'}</option>
+			     <option value="3"$mts4>$smtp_txt{'tlsnet'}</option>
		   </select></div>
	 <br />
		   <div class="setting_cell">$admin_txt{'354'}</div>
@@ -1467,12 +1469,12 @@
\$default_template = "$default_template";		  # Default Forum Template
\$mailprog = "$mailprog";					# Location of your sendmail program
-\$smtp_server = "$smtp_server";					  # Address of your SMTP-Server
+\$smtp_server = "$smtp_server";					  # Address of your SMTP-Server (for Net::SMTP::TLS, specify port number with a :<portnum> at the end)
\$smtp_auth_required = $smtp_auth_required;		# Set to 1 if the SMTP server requires Authorisation
\$authuser = q^$authuser^;				     # Username for SMTP authorisation
\$authpass = q^$authpass^;				     # Password for SMTP authorisation
\$webmaster_email = q^$webmaster_email^;		   # Your email address. (eg: \$webmaster_email = q^admin\@host.com^;)
-\$mailtype = $mailtype;						    # Mail program to use: 0 = sendmail, 1 = SMTP, 2 = Net::SMTP
+\$mailtype = $mailtype;						    # Mail program to use: 0 = sendmail, 1 = SMTP, 2 = Net::SMTP, 3 = Net::SMTP::TLS 



########## Layout ##########

diff -u Admin.lng~ Admin.lng
--- Admin.lng~  2005-11-28 19:59:40.000000000 -0800
+++ Admin.lng   2006-11-20 11:12:22.000000000 -0800
@@ -1062,6 +1062,7 @@
'sendmail' => "Unix/Linux Sendmail",
'smtp' => "YaBB SMTP Engine",
'net' => "Net::SMTP (Perl Module)",
+'tlsnet' => "Net::SMTP::TLS (Perl Module)",
'auto' => "AUTO",
'cram' => "CRAM-MD5",
'login' => "LOGIN",
Code
Select All
diff -u ./Sources/Subs.pl~ ./Sources/Subs.pl
--- ./Sources/Subs.pl~  2005-11-28 19:59:40.000000000 -0800
+++ ./Sources/Subs.pl   2006-11-20 11:25:35.000000000 -0800
@@ -748,6 +748,35 @@
		   }
		   return 1;
	 }
+	 if ($mailtype == 3) {
+		   eval q^
+			     use Net::SMTP::TLS;
+			     my $port = 25;
+			     if ($smtp_server =~ /:(\d+)$/) {
+					 $port = $1;
+					 $smtp_server =~ s/:\d+$//g;
+			     }
+			     my $smtp = Net::SMTP::TLS->new($smtp_server, Port => $port, User => $authuser, Password => $authpass, Debug => 0) || die "unable to create Net::SMTP::TLS object $smtp_server $port.";
+			     $smtp->mail($from);
+			     foreach (split(/, /, $to)) {
+					 $smtp->to($_);
+			     }
+			     $smtp->data();
+			     $smtp->datasend("To: $toheader\r\n");
+			     $smtp->datasend("From: $fromheader\r\n");
+			     $smtp->datasend("X-Mailer: YaBB Net::SMTP\r\n");
+			     $smtp->datasend("Subject: $subject\r\n");
+			     $smtp->datasend("\r\n");
+			     $smtp->datasend($message);
+			     $smtp->dataend();
+			     $smtp->quit();
+		   ^;
+		   if ($@) {
+			     &fatal_error("\n<br />Net::SMTP fatal error: $@\n<br />");
+			     return -77;
+		   }
+		   return 1;
+	 }
	 if ($mailtype == 0) {
		   $to =~ s/,//g;
		   open(MAIL, "| $mailprog  $to"); 



Note: The above code changes have been included in YaBB Version Y2.3.1
« Last Edit: Feb 18th, 2009 at 8:56pm by »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Print
 
  « Board Index ‹ Board  ^Top