rework sender/from/replyTo Information on notification

This commit is contained in:
Klaus Leithoff 2014-11-18 10:50:35 +00:00
parent 7fd377df56
commit 97acbbb70f
2 changed files with 38 additions and 5 deletions

View File

@ -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)
@ -130,8 +145,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));
}
}

View File

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