diff --git a/config.inc.php b/config.inc.php index f7328a64..d1e76e18 100644 --- a/config.inc.php +++ b/config.inc.php @@ -150,6 +150,12 @@ $CONF['database_tables'] = array ( // Leave blank to send email from the logged-in Admin's Email address. $CONF['admin_email'] = ''; +// Define the smtp password for admin_email. +// This will be used to send emails from to create mailboxes and +// from Send Email / Broadcast message pages. +// Leave blank to send emails without authentification +$CONF['admin_smtp_password'] = ''; + // Site admin name // This will be used as signature in notification messages $CONF['admin_name'] = 'Postmaster'; diff --git a/functions.inc.php b/functions.inc.php index 18f2dec6..3fbbee19 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1357,11 +1357,12 @@ function to64($v, $n) { * @param String - To: * @param String - From: * @param String - Subject: (if called with 4 parameters) or full mail body (if called with 3 parameters) + * @param String (optional) - Password * @param String (optional, but recommended) - mail body * @return bool - true on success, otherwise false * TODO: Replace this with something decent like PEAR::Mail or Zend_Mail. */ -function smtp_mail($to, $from, $data, $body = "") { +function smtp_mail($to, $from, $data, $password = "", $body = "") { global $CONF; $smtpd_server = $CONF['smtp_server']; $smtpd_port = $CONF['smtp_port']; @@ -1399,6 +1400,16 @@ function smtp_mail($to, $from, $data, $body = "") { smtp_get_response($fh); fputs($fh, "EHLO $smtp_server\r\n"); smtp_get_response($fh); + + if (!empty($password)) { + fputs($fh,"AUTH LOGIN\r\n"); + smtp_get_response($fh); + fputs($fh, base64_encode($from) . "\r\n"); + smtp_get_response($fh); + fputs($fh, base64_encode($password) . "\r\n"); + smtp_get_response($fh); + } + fputs($fh, "MAIL FROM:<$from>\r\n"); smtp_get_response($fh); fputs($fh, "RCPT TO:<$to>\r\n"); @@ -1429,6 +1440,16 @@ function smtp_get_admin_email() { } } +/** + * smtp_get_admin_password + * Action: Get smtp password for admin email + * Call: smtp_get_admin_password + * @return string - admin smtp password + */ +function smtp_get_admin_password() { + return Config::read_string('admin_smtp_password'); +} + // // smtp_get_response diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index fc16c62f..b811f888 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -463,7 +463,7 @@ class MailboxHandler extends PFAHandler { $fSubject = Config::lang('pSendmail_subject_text'); $fBody = Config::read('welcome_text'); - if (!smtp_mail($fTo, $fFrom, $fSubject, $fBody)) { + if (!smtp_mail($fTo, $fFrom, $fSubject, smtp_get_admin_password(), $fBody)) { $this->errormsg[] = Config::lang_f('pSendmail_result_error', $this->id); return false; } diff --git a/public/broadcast-message.php b/public/broadcast-message.php index b2fe38f0..f3ed90ac 100644 --- a/public/broadcast-message.php +++ b/public/broadcast-message.php @@ -90,7 +90,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { $fHeaders .= $b_message; - if (!smtp_mail($fTo, $smtp_from_email, $fHeaders)) { + if (!smtp_mail($fTo, $smtp_from_email, $fHeaders, smtp_get_admin_password())) { flash_error(Config::lang_f('pSendmail_result_error', $fTo)); } else { flash_info(Config::lang_f('pSendmail_result_success', $fTo)); diff --git a/public/sendmail.php b/public/sendmail.php index e711e72a..753653d5 100644 --- a/public/sendmail.php +++ b/public/sendmail.php @@ -62,7 +62,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { } if ($error != 1) { - if (!smtp_mail($fTo, $fFrom, $fSubject, $tBody)) { + if (!smtp_mail($fTo, $fFrom, $fSubject, smtp_get_admin_password(), $tBody)) { flash_error(Config::lang_f('pSendmail_result_error', $fTo)); } else { flash_info(Config::lang_f('pSendmail_result_success', $fTo)); diff --git a/public/users/password-recover.php b/public/users/password-recover.php index 54d14b57..dfb23f45 100644 --- a/public/users/password-recover.php +++ b/public/users/password-recover.php @@ -45,7 +45,7 @@ function sendCodebyEmail($to, $username, $code) { $url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/password-change.php?username=' . urlencode($username) . '&code=' . $code; - return smtp_mail($to, Config::read('admin_email'), Config::Lang('pPassword_welcome'), Config::lang_f('pPassword_recovery_email_body', $url)); + return smtp_mail($to, Config::read('admin_email'), Config::Lang('pPassword_welcome'), Config::read('admin_smtp_password'), Config::lang_f('pPassword_recovery_email_body', $url)); } function sendCodebySMS($to, $username, $code) {