Add option to use smtp password when sending admin emails (fixes #272)

pull/277/head
Felix Ableitner 6 years ago
parent 55858bf3a0
commit 600248e955

@ -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';

@ -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

@ -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;
}

@ -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));

@ -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));

@ -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) {

Loading…
Cancel
Save