[Home]WikiPatches/UseNetSmtp

UseModWiki | WikiPatches | RecentChanges | Preferences

Theses patches modify sending of the e-mail notifications to use a pure Perl mailing solution. It makes the script to use the package Net::SMTP instead of the sendmail executable if the configuration variable $SmtpServer is not empty. Net::SMTP is installed more frequently than Mail::Sendmail or Mail::Sender, it is a standard part of a most distributions.

You have to set $SmtpServer to a SMTP server valid at your site to enable usage of Net::Smtp. Usage of sendmail is suppressed only in the first patch and it can be turned on again by setting $SmtpServer to empty string. The second patch gets rid of sendmail copmpletely (removing the dependency on the external process).

The change (only one of the patches, not both of them on a one wiki engine... ;-) should be easy applicable from the unified diffs below; they were produced from the vanilla usemod-wiki 0.92.

--FerdinandPrantl

Optional usage of Net::SMTP:

--- wiki.pl.orig	Wed Mar 26 20:02:46 2003
+++ wiki.pl	Wed Mar 26 20:24:07 2003
@@ -37,7 +37,7 @@
   $LogoUrl $RcDefault $IndentLimit $RecentTop $EditAllowed $UseDiff
   $UseSubpage $UseCache $RawHtml $SimpleLinks $NonEnglish $LogoLeft
   $KeepDays $HtmlTags $HtmlLinks $UseDiffLog $KeepMajor $KeepAuthor
-  $FreeUpper $EmailNotify $SendMail $EmailFrom $FastGlob $EmbedWiki
+  $FreeUpper $EmailNotify $SendMail $SmtpServer $EmailFrom $FastGlob $EmbedWiki
   $ScriptTZ $BracketText $UseAmPm $UseConfig $UseIndex $UseLookup
   $RedirType $AdminPass $EditPass $UseHeadings $NetworkFile $BracketWiki
   $FreeLinks $WikiLinks $AdminDelete $FreeLinkPattern $RCName $RunCGI
@@ -78,6 +78,7 @@
 $NotFoundPg  = "";              # Page for not-found links ("" for blank pg)
 $EmailFrom   = "Wiki";          # Text for "From: " field of email notes.
 $SendMail    = "/usr/sbin/sendmail";  # Full path to sendmail executable
+$SmtpServer  = "";              # hostname of the SMTP server (if empty, defaults to sendmail)
 $FooterNote  = "";              # HTML for bottom of every page
 $EditNote    = "";              # HTML notice above buttons on edit page
 $MaxPost     = 1024 * 210;      # Maximum 210K posts (about 200K for pages)
@@ -3331,25 +3332,41 @@
 
 # Translation note: the email messages are still sent in English
 # Send an email message.
+use Net::SMTP;
 sub SendEmail {
   my ($to, $from, $reply, $subject, $message) = @_;
     ### debug
     ## print "Content-type: text/plain\n\n";
     ## print " to: '$to'\n";
     ## return;
-  # sendmail options:
-  #    -odq : send mail to queue (i.e. later when convenient)
-  #    -oi  : do not wait for "." line to exit
-  #    -t   : headers determine recipient.
-  open (SENDMAIL, "| $SendMail -oi -t ") or die "Can't send email: $!\n";
-  print SENDMAIL <<"EOF";
+  if ($SmtpServer ne "") {
+    my $smtp = new Net::SMTP($SmtpServer);
+    defined($smtp) or die "Can't send email: $!\n";
+    $smtp->mail($from);
+    $smtp->to($to);
+    $smtp->data();
+    $smtp->datasend("To: $to\n");
+    $smtp->datasend("Subject: $subject\n");
+    $smtp->datasend("\n");
+    $smtp->datasend("$message\n");
+    $smtp->dataend();
+    $smtp->quit;
+  }
+  else {
+    # sendmail options:
+    #    -odq : send mail to queue (i.e. later when convenient)
+    #    -oi  : do not wait for "." line to exit
+    #    -t   : headers determine recipient.
+    open (SENDMAIL, "| $SendMail -oi -t ") or die "Can't send email: $!\n";
+    print SENDMAIL <<"EOF";
 From: $from
 To: $to
 Reply-to: $reply
 Subject: $subject\n
 $message
 EOF
-  close(SENDMAIL) or warn "sendmail didn't close nicely";
+    close(SENDMAIL) or warn "sendmail didn't close nicely";
+  }
 }
 
 ## Email folks who want to know a note that a page has been modified. - JimM.

Usage of Net::SMTP only:

--- wiki.pl.orig	Wed Mar 26 20:02:46 2003
+++ wiki.pl	Thu Mar 27 07:22:17 2003
@@ -37,7 +37,7 @@
   $LogoUrl $RcDefault $IndentLimit $RecentTop $EditAllowed $UseDiff
   $UseSubpage $UseCache $RawHtml $SimpleLinks $NonEnglish $LogoLeft
   $KeepDays $HtmlTags $HtmlLinks $UseDiffLog $KeepMajor $KeepAuthor
-  $FreeUpper $EmailNotify $SendMail $EmailFrom $FastGlob $EmbedWiki
+  $FreeUpper $EmailNotify $SmtpServer $EmailFrom $FastGlob $EmbedWiki
   $ScriptTZ $BracketText $UseAmPm $UseConfig $UseIndex $UseLookup
   $RedirType $AdminPass $EditPass $UseHeadings $NetworkFile $BracketWiki
   $FreeLinks $WikiLinks $AdminDelete $FreeLinkPattern $RCName $RunCGI
@@ -77,7 +77,7 @@
 $StyleSheet  = "";              # URL for CSS stylesheet (like "/wiki.css")
 $NotFoundPg  = "";              # Page for not-found links ("" for blank pg)
 $EmailFrom   = "Wiki";          # Text for "From: " field of email notes.
-$SendMail    = "/usr/sbin/sendmail";  # Full path to sendmail executable
+$SmtpServer  = "";              # hostname of the SMTP server
 $FooterNote  = "";              # HTML for bottom of every page
 $EditNote    = "";              # HTML notice above buttons on edit page
 $MaxPost     = 1024 * 210;      # Maximum 210K posts (about 200K for pages)
@@ -3331,25 +3331,24 @@
 
 # Translation note: the email messages are still sent in English
 # Send an email message.
+use Net::SMTP;
 sub SendEmail {
   my ($to, $from, $reply, $subject, $message) = @_;
     ### debug
     ## print "Content-type: text/plain\n\n";
     ## print " to: '$to'\n";
     ## return;
-  # sendmail options:
-  #    -odq : send mail to queue (i.e. later when convenient)
-  #    -oi  : do not wait for "." line to exit
-  #    -t   : headers determine recipient.
-  open (SENDMAIL, "| $SendMail -oi -t ") or die "Can't send email: $!\n";
-  print SENDMAIL <<"EOF";
-From: $from
-To: $to
-Reply-to: $reply
-Subject: $subject\n
-$message
-EOF
-  close(SENDMAIL) or warn "sendmail didn't close nicely";
+  my $smtp = new Net::SMTP($SmtpServer);
+  defined($smtp) or die "Can't send email: $!\n";
+  $smtp->mail($from);
+  $smtp->to($to);
+  $smtp->data();
+  $smtp->datasend("To: $to\n");
+  $smtp->datasend("Subject: $subject\n");
+  $smtp->datasend("\n");
+  $smtp->datasend("$message\n");
+  $smtp->dataend();
+  $smtp->quit;
 }
 
 ## Email folks who want to know a note that a page has been modified. - JimM.

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited March 27, 2003 6:29 am by HOST.133.221.ixos.de (diff)
Search: