Additions:
classes/trssmailer.php - Created class TTRSS mailer which extends phpmailer and sets the default mail settings upon instantiation. Class includes quickmail function that allows for a quick email send with no extra configurion necessary. Changes: config.php-dist - Added the smtp port option include/digest.php - Converted it to use the new ttrrssmailer class include/sanity_config.php - Added the smtp port option to the sanity check plugins/mail/init.php - Modified to use ttrssmailer class. This particular configuration shows a hybrid use case. register.php = Modified to use ttrssmailer class. All code was tested and functioned on my local machine.
This commit is contained in:
parent
9d9432dab8
commit
1b2afd2bd3
|
@ -9,3 +9,4 @@ lock/*
|
||||||
tags
|
tags
|
||||||
cache/htmlpurifier/*/*ser
|
cache/htmlpurifier/*/*ser
|
||||||
lib/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/*/*ser
|
lib/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/*/*ser
|
||||||
|
web.config
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
/* @class ttrssMailer
|
||||||
|
* @brief A TTRSS extension to the PHPMailer class
|
||||||
|
* Configures default values through the __construct() function
|
||||||
|
* @author Derek Murawsky
|
||||||
|
* @version .1 (alpha)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
require_once 'lib/phpmailer/class.phpmailer.php';
|
||||||
|
require_once "config.php";
|
||||||
|
|
||||||
|
class ttrssMailer extends PHPMailer {
|
||||||
|
|
||||||
|
//define all items that we want to override with defaults in PHPMailer
|
||||||
|
public $From = SMTP_FROM_ADDRESS;
|
||||||
|
public $FromName = SMTP_FROM_NAME;
|
||||||
|
public $CharSet = "UTF-8";
|
||||||
|
public $PluginDir = "lib/phpmailer/";
|
||||||
|
public $ContentType = "text/html"; //default email type is HTML
|
||||||
|
public $Host;
|
||||||
|
public $Port;
|
||||||
|
public $SMTPAuth=False;
|
||||||
|
public $Username;
|
||||||
|
public $Password;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->SetLanguage("en", "lib/phpmailer/language/");
|
||||||
|
//if SMTP_HOST is specified, use SMTP to send mail directly
|
||||||
|
if (SMTP_HOST) {
|
||||||
|
$Host = SMTP_HOST;
|
||||||
|
$Mailer = "smtp";
|
||||||
|
}
|
||||||
|
//if SMTP_PORT is specified, assign it. Otherwise default to port 25
|
||||||
|
if(SMTP_PORT){
|
||||||
|
$Port = SMTP_PORT;
|
||||||
|
}else{
|
||||||
|
$Port = "25";
|
||||||
|
}
|
||||||
|
|
||||||
|
//if SMTP_LOGIN is specified, set credentials and enable auth
|
||||||
|
if(SMTP_LOGIN){
|
||||||
|
$SMTPAuth = true;
|
||||||
|
$Username = SMTP_LOGIN;
|
||||||
|
$Password = SMTP_PASSWORD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* @brief a simple mail function to send email using the defaults
|
||||||
|
* This will send an HTML email using the configured defaults
|
||||||
|
* @param $toAddress A string with the recipients email address
|
||||||
|
* @param $toName A string with the recipients name
|
||||||
|
* @param $subject A string with the emails subject
|
||||||
|
* @param $body A string containing the body of the email
|
||||||
|
*/
|
||||||
|
public function quickMail ($toAddress, $toName, $subject, $body, $altbody=""){
|
||||||
|
$this->addAddress($toAddress, $toName);
|
||||||
|
$this->Subject = $subject;
|
||||||
|
$this->Body = $body;
|
||||||
|
$rc=$this->send();
|
||||||
|
return $rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -157,6 +157,9 @@
|
||||||
define('SMTP_HOST', '');
|
define('SMTP_HOST', '');
|
||||||
// SMTP Host to send outgoing mail. Blank - use system MTA.
|
// SMTP Host to send outgoing mail. Blank - use system MTA.
|
||||||
|
|
||||||
|
define('SMTP_PORT','');
|
||||||
|
// SMTP port to sent outgoing mail. Default is 25.
|
||||||
|
|
||||||
define('SMTP_LOGIN', '');
|
define('SMTP_LOGIN', '');
|
||||||
define('SMTP_PASSWORD', '');
|
define('SMTP_PASSWORD', '');
|
||||||
// These two options enable SMTP authentication when sending
|
// These two options enable SMTP authentication when sending
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
function send_headlines_digests($link, $debug = false) {
|
function send_headlines_digests($link, $debug = false) {
|
||||||
|
|
||||||
require_once 'lib/phpmailer/class.phpmailer.php';
|
require_once 'classes/ttrssmailer.php';
|
||||||
|
|
||||||
$user_limit = 15; // amount of users to process (e.g. emails to send out)
|
$user_limit = 15; // amount of users to process (e.g. emails to send out)
|
||||||
$limit = 1000; // maximum amount of headlines to include
|
$limit = 1000; // maximum amount of headlines to include
|
||||||
|
@ -50,31 +50,9 @@
|
||||||
|
|
||||||
if ($headlines_count > 0) {
|
if ($headlines_count > 0) {
|
||||||
|
|
||||||
$mail = new PHPMailer();
|
$mail = new ttrssMailer();
|
||||||
|
|
||||||
$mail->PluginDir = "lib/phpmailer/";
|
$rc = $mail->quickMail($line["email"], $line["login"] , DIGEST_SUBJECT, $digest, $digest_text);
|
||||||
$mail->SetLanguage("en", "lib/phpmailer/language/");
|
|
||||||
|
|
||||||
$mail->CharSet = "UTF-8";
|
|
||||||
|
|
||||||
$mail->From = SMTP_FROM_ADDRESS;
|
|
||||||
$mail->FromName = SMTP_FROM_NAME;
|
|
||||||
$mail->AddAddress($line["email"], $line["login"]);
|
|
||||||
|
|
||||||
if (SMTP_HOST) {
|
|
||||||
$mail->Host = SMTP_HOST;
|
|
||||||
$mail->Mailer = "smtp";
|
|
||||||
$mail->SMTPAuth = SMTP_LOGIN != '';
|
|
||||||
$mail->Username = SMTP_LOGIN;
|
|
||||||
$mail->Password = SMTP_PASSWORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail->IsHTML(true);
|
|
||||||
$mail->Subject = DIGEST_SUBJECT;
|
|
||||||
$mail->Body = $digest;
|
|
||||||
$mail->AltBody = $digest_text;
|
|
||||||
|
|
||||||
$rc = $mail->Send();
|
|
||||||
|
|
||||||
if (!$rc && $debug) print "ERROR: " . $mail->ErrorInfo;
|
if (!$rc && $debug) print "ERROR: " . $mail->ErrorInfo;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<?php # This file has been generated at: Sat Feb 9 22:34:30 MSK 2013
|
<?php # This file has been generated at: Sat Feb 9 22:34:30 MSK 2013
|
||||||
define('GENERATED_CONFIG_CHECK', 26);
|
define('GENERATED_CONFIG_CHECK', 26);
|
||||||
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_HOST', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CHECK_FOR_NEW_VERSION', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'CONFIG_VERSION'); ?>
|
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_HOST', 'SMTP_PORT', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CHECK_FOR_NEW_VERSION', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'CONFIG_VERSION'); ?>
|
||||||
|
|
|
@ -137,7 +137,7 @@ class Mail extends Plugin {
|
||||||
function sendEmail() {
|
function sendEmail() {
|
||||||
$secretkey = $_REQUEST['secretkey'];
|
$secretkey = $_REQUEST['secretkey'];
|
||||||
|
|
||||||
require_once 'lib/phpmailer/class.phpmailer.php';
|
require_once 'classes/ttrssmailer.php';
|
||||||
|
|
||||||
$reply = array();
|
$reply = array();
|
||||||
|
|
||||||
|
@ -146,35 +146,18 @@ class Mail extends Plugin {
|
||||||
|
|
||||||
$_SESSION['email_secretkey'] = '';
|
$_SESSION['email_secretkey'] = '';
|
||||||
|
|
||||||
$destination = $_REQUEST['destination'];
|
|
||||||
$subject = $_REQUEST['subject'];
|
|
||||||
$content = $_REQUEST['content'];
|
|
||||||
|
|
||||||
$replyto = strip_tags($_SESSION['email_replyto']);
|
$replyto = strip_tags($_SESSION['email_replyto']);
|
||||||
$fromname = strip_tags($_SESSION['email_fromname']);
|
$fromname = strip_tags($_SESSION['email_fromname']);
|
||||||
|
|
||||||
$mail = new PHPMailer();
|
$mail = new ttrssMailer();
|
||||||
|
|
||||||
$mail->PluginDir = "lib/phpmailer/";
|
|
||||||
$mail->SetLanguage("en", "lib/phpmailer/language/");
|
|
||||||
|
|
||||||
$mail->CharSet = "UTF-8";
|
|
||||||
|
|
||||||
$mail->From = $replyto;
|
$mail->From = $replyto;
|
||||||
$mail->FromName = $fromname;
|
$mail->FromName = $fromname;
|
||||||
$mail->AddAddress($destination);
|
$mail->AddAddress($_REQUEST['destination']);
|
||||||
|
|
||||||
if (SMTP_HOST) {
|
|
||||||
$mail->Host = SMTP_HOST;
|
|
||||||
$mail->Mailer = "smtp";
|
|
||||||
$mail->SMTPAuth = SMTP_LOGIN != '';
|
|
||||||
$mail->Username = SMTP_LOGIN;
|
|
||||||
$mail->Password = SMTP_PASSWORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail->IsHTML(false);
|
$mail->IsHTML(false);
|
||||||
$mail->Subject = $subject;
|
$mail->Subject = $_REQUEST['subject'];
|
||||||
$mail->Body = $content;
|
$mail->Body = $_REQUEST['content'];
|
||||||
|
|
||||||
$rc = $mail->Send();
|
$rc = $mail->Send();
|
||||||
|
|
||||||
|
|
59
register.php
59
register.php
|
@ -7,7 +7,7 @@
|
||||||
set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
|
set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
|
||||||
get_include_path());
|
get_include_path());
|
||||||
|
|
||||||
require_once 'lib/phpmailer/class.phpmailer.php';
|
require_once 'classes/ttrssmailer.php';
|
||||||
|
|
||||||
require_once "functions.php";
|
require_once "functions.php";
|
||||||
require_once "sessions.php";
|
require_once "sessions.php";
|
||||||
|
@ -306,33 +306,15 @@
|
||||||
"\n".
|
"\n".
|
||||||
"If that wasn't you, just ignore this message. Thanks.";
|
"If that wasn't you, just ignore this message. Thanks.";
|
||||||
|
|
||||||
$mail = new PHPMailer();
|
$mail = new ttrssMailer();
|
||||||
|
$mail->IsHTML(false);
|
||||||
$mail->PluginDir = "lib/phpmailer/";
|
$rc = $mail->quickMail($email, "", "Registration information for Tiny Tiny RSS", $reg_text, false);
|
||||||
$mail->SetLanguage("en", "lib/phpmailer/language/");
|
|
||||||
|
|
||||||
$mail->CharSet = "UTF-8";
|
|
||||||
|
|
||||||
$mail->From = SMTP_FROM_ADDRESS;
|
|
||||||
$mail->FromName = SMTP_FROM_NAME;
|
|
||||||
$mail->AddAddress($email);
|
|
||||||
|
|
||||||
if (SMTP_HOST) {
|
|
||||||
$mail->Host = SMTP_HOST;
|
|
||||||
$mail->Mailer = "smtp";
|
|
||||||
$mail->Username = SMTP_LOGIN;
|
|
||||||
$mail->Password = SMTP_PASSWORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
// $mail->IsHTML(true);
|
|
||||||
$mail->Subject = "Registration information for Tiny Tiny RSS";
|
|
||||||
$mail->Body = $reg_text;
|
|
||||||
// $mail->AltBody = $digest_text;
|
|
||||||
|
|
||||||
$rc = $mail->Send();
|
|
||||||
|
|
||||||
if (!$rc) print_error($mail->ErrorInfo);
|
if (!$rc) print_error($mail->ErrorInfo);
|
||||||
|
|
||||||
|
unset($reg_text);
|
||||||
|
unset($mail);
|
||||||
|
unset($rc);
|
||||||
$reg_text = "Hi!\n".
|
$reg_text = "Hi!\n".
|
||||||
"\n".
|
"\n".
|
||||||
"New user had registered at your Tiny Tiny RSS installation.\n".
|
"New user had registered at your Tiny Tiny RSS installation.\n".
|
||||||
|
@ -340,30 +322,11 @@
|
||||||
"Login: $login\n".
|
"Login: $login\n".
|
||||||
"Email: $email\n";
|
"Email: $email\n";
|
||||||
|
|
||||||
$mail = new PHPMailer();
|
|
||||||
|
|
||||||
$mail->PluginDir = "lib/phpmailer/";
|
$mail = new ttrssMailer();
|
||||||
$mail->SetLanguage("en", "lib/phpmailer/language/");
|
$mail->IsHTML(false);
|
||||||
|
$rc = $mail->quickMail(REG_NOTIFY_ADDRESS, "", "Registration notice for Tiny Tiny RSS", $reg_text, false);
|
||||||
$mail->CharSet = "UTF-8";
|
if (!$rc) print_error($mail->ErrorInfo);
|
||||||
|
|
||||||
$mail->From = SMTP_FROM_ADDRESS;
|
|
||||||
$mail->FromName = SMTP_FROM_NAME;
|
|
||||||
$mail->AddAddress(REG_NOTIFY_ADDRESS);
|
|
||||||
|
|
||||||
if (SMTP_HOST) {
|
|
||||||
$mail->Host = SMTP_HOST;
|
|
||||||
$mail->Mailer = "smtp";
|
|
||||||
$mail->Username = SMTP_LOGIN;
|
|
||||||
$mail->Password = SMTP_PASSWORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
// $mail->IsHTML(true);
|
|
||||||
$mail->Subject = "Registration notice for Tiny Tiny RSS";
|
|
||||||
$mail->Body = $reg_text;
|
|
||||||
// $mail->AltBody = $digest_text;
|
|
||||||
|
|
||||||
$rc = $mail->Send();
|
|
||||||
|
|
||||||
print_notice(__("Account created successfully."));
|
print_notice(__("Account created successfully."));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue