From ba3cde9c175df2434668181f46e0f681bbc3d938 Mon Sep 17 00:00:00 2001 From: "Nicholas Pisarro, Jr" Date: Fri, 27 Feb 2004 12:48:07 +0000 Subject: [PATCH] Added the ability to do an authenticated SMTP login to send mail. * by setting the array variable '$wgSMTP' in Local settings, the source will use PEAR:mail to connect to a specific SMTP server to send mail. It will use an authenticated login, if requested. * Example: $wgSMTP = array ( "host" => "smtp.wherever.com", "IDHost" => "mail.wikipedia.org", "port" => "25", "auth" => true, "username" => "mailID", "password" => "mailPswd"); --- includes/DefaultSettings.php | 4 +++ includes/SpecialEmailuser.php | 29 ++++++++---------- includes/SpecialUserlogin.php | 8 ++--- includes/UserMailer.php | 58 +++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 includes/UserMailer.php diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index ea1515a41b..695d038cb0 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -31,6 +31,10 @@ $wgTmpDirectory = "{$wgUploadDirectory}/tmp"; $wgEmergencyContact = "wikiadmin@" . getenv( "SERVER_NAME" ); $wgPasswordSender = "Wikipedia Mail "; +# For using a direct (authenticated) SMTP server connection. +# "host" => 'SMTP domain', "IDHost" => 'domain for MessageID', "port" => "25", "auth" => true/false, "username" => user, "password" => password +$wgSMTP = false; + # MySQL settings # $wgDBserver = "localhost"; diff --git a/includes/SpecialEmailuser.php b/includes/SpecialEmailuser.php index 5fac3c89af..bdd6217f78 100644 --- a/includes/SpecialEmailuser.php +++ b/includes/SpecialEmailuser.php @@ -1,5 +1,7 @@ getName() ) . " <" . $wgUser->getEmail() . ">"; - $to = wfQuotedPrintable( $this->mAddress ); - - $headers = - "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" . - "Content-transfer-encoding: 8bit\r\n" . - "From: {$from}\r\n" . - "Reply-To: {$from}\r\n" . - "To: {$to}\r\n" . - "X-Mailer: MediaWiki interuser e-mailer"; - mail( $this->mAddress, wfQuotedPrintable( $wpSubject ), $wpText, $headers ); - - - $success = wfLocalUrl( $wgLang->specialPage( "Emailuser" ), - "target={$target}&action=success" ); - $wgOut->redirect( $success ); + + $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $wpSubject ), $wpText ); + + if (! $mailResult) + { + $success = wfLocalUrl( $wgLang->specialPage( "Emailuser" ), + "target={$target}&action=success" ); + $wgOut->redirect( $success ); + } + else + $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult); } function showSuccess() diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 0ef1d3ba1e..bdb389ebcc 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -1,5 +1,7 @@ getName(), $np ); - mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m, - "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" . - "Content-transfer-encoding: 8bit\r\n" . - "From: $wgPasswordSender" ); + userMailer( $u->getEmail(), $wgPasswordSender, wfMsg( "passwordremindertitle" ), $m ); return $u; } diff --git a/includes/UserMailer.php b/includes/UserMailer.php new file mode 100644 index 0000000000..5a82988d8c --- /dev/null +++ b/includes/UserMailer.php @@ -0,0 +1,58 @@ +getName() . "@" . $wgSMTP["IDHost"] . ">"; + $headers["X-Mailer"] = "MediaWiki interuser e-mailer"; + + // Create the mail object using the Mail::factory method + $mail_object =& Mail::factory("smtp", $wgSMTP); + + $mailResult =& $mail_object->send($to, $headers, $body); + + # Based on the result return an error string, + if ($mailResult === true) + return ""; + else if (is_object($mailResult)) + return $mailResult->getMessage(); + else + return "Mail object return unknown error."; + } + + else + { + $headers = + "MIME-Version: 1.0\r\n" . + "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" . + "Content-transfer-encoding: 8bit\r\n" . + "From: {$from}\r\n" . + "Reply-To: {$from}\r\n" . + "To: {$qto}\r\n" . + "X-Mailer: MediaWiki interuser e-mailer"; + mail( $to, $subject, $body, $headers ); + + return ""; + } +} + +?> \ No newline at end of file -- 2.20.1