From 508537606b8d53c2a4b490f5b7b3ddfb104ac3b6 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Tue, 18 Nov 2014 11:04:22 +0000 Subject: [PATCH] rework sender/from/replyTo Information on notification --- .../inc/class.notifications_email.inc.php | 21 ++++++++++++++++-- phpgwapi/inc/class.send.inc.php | 22 ++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/notifications/inc/class.notifications_email.inc.php b/notifications/inc/class.notifications_email.inc.php index e49a96d2fe..dcd6578c08 100644 --- a/notifications/inc/class.notifications_email.inc.php +++ b/notifications/inc/class.notifications_email.inc.php @@ -99,8 +99,23 @@ class notifications_email implements notifications_iface { $this->mail->AddCustomHeader('X-EGroupware-Install: '.$GLOBALS['egw_info']['server']['install_id'].'@'.$GLOBALS['egw_info']['server']['default_domain']); //$this->mail->AddCustomHeader('X-EGroupware-URL: notification-mail'); //$this->mail->AddCustomHeader('X-EGroupware-Tracker: notification-mail'); - $this->mail->From = $this->sender->account_email; - $this->mail->FromName = $this->sender->account_fullname; + //error_log(__METHOD__.__LINE__."preparing notification message via email.".array2string($this->mail)); + if (!$this->mail->From) + { + $this->mail->From = $this->sender->account_email; + $this->mail->FromName = $this->sender->account_fullname; + } + else + { + if ($this->sender->account_email) + { + $this->mail->ClearReplyTos(); + $this->mail->AddReplyTo($this->sender->account_email,$this->sender->account_fullname); + // as we set the replyTo, we set (fake) the FromName accordingly + if ($this->sender->account_fullname) $this->mail->FromName = $this->sender->account_fullname; + } + } + //error_log(__METHOD__.__LINE__."preparing notification message via email.".array2string($this->mail)); $this->mail->Subject = $_subject; // add iCal invitation as mulitpart alternative for calendar notifications if ($_attachments && stripos($_attachments[0]->type,"text/calendar; method=")!==false) @@ -127,8 +142,10 @@ class notifications_email implements notifications_iface { } } } + //error_log(__METHOD__.__LINE__."about sending notification message via email.".array2string($this->mail)); if(!$error=$this->mail->Send()) { + //error_log(__METHOD__.__LINE__." Failed sending notification message via email.$error".array2string($this->mail->ErrorInfo)); throw new Exception("Failed sending notification message via email.$error".print_r($this->mail->ErrorInfo,true)); } } diff --git a/phpgwapi/inc/class.send.inc.php b/phpgwapi/inc/class.send.inc.php index 17ec5617a5..7e3a912a14 100644 --- a/phpgwapi/inc/class.send.inc.php +++ b/phpgwapi/inc/class.send.inc.php @@ -60,10 +60,26 @@ class send extends egw_mailer $this->Username = $account->acc_smtp_username; $this->Password = $account->acc_smtp_password; $this->defaultDomain = $account->acc_domain; + // we do not want to use the phpmailer defaults, as it is bound to fail anyway + // !from should be connected to the account used! + $this->From = ''; + $this->FromName = ''; // use smpt-username as sender, if available, but only if it is a full email address - $this->Sender = $account->acc_smtp_username && strpos($account->acc_smtp_username, '@') !== false ? - $account->acc_smtp_username : $account->acc_ident_email; - + // we use setFrom as of from now on as it sets From, FromName and Sender + // error_log(__METHOD__.__LINE__.array2string($account)); + $Sender = $account->acc_smtp_username && strpos($account->acc_smtp_username, '@') !== false ? + $account->acc_smtp_username : $account->ident_email; + /*emailadmin_account Object has some possible info on the accounts realname + [acc_name] => example given (mail@domain.suffix) + [ident_realname] => example given + [ident_email] => mail@domain.suffix (maybe this is the content of $Sender !) + [ident_org] => not considered + [ident_name] => example + */ + $Name = ($account['ident_realname']?$account['ident_realname']:($account['ident_name']?$account['ident_name']: + ($account['acc_name']?$account['acc_name']:$Sender))); + //error_log(__METHOD__.__LINE__.$Sender.','.$Name); + $this->setFrom($Sender,$Name); $this->Hostname = $GLOBALS['egw_info']['server']['hostname']; if ($this->debug) error_log(__METHOD__."() initialised egw_mailer with ".array2string($this)." from mail default account ".array2string($account->params));