ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilMailMimeTransportBase Class Reference

Class ilMailMimeTransportBase. More...

+ Inheritance diagram for ilMailMimeTransportBase:
+ Collaboration diagram for ilMailMimeTransportBase:

Public Member Functions

 __construct (ilSetting $settings, ilAppEventHandler $eventHandler)
 ilMailMimeTransportBase constructor. More...
 
 send (ilMimeMail $mail)
 
Parameters
ilMimeMail$mail
Returns
bool
More...
 
 send (ilMimeMail $mail)
 

Protected Member Functions

 getMailer ()
 
 setMailer (PHPMailer $mailer)
 
 resetMailer ()
 
 onBeforeSend ()
 

Protected Attributes

 $mailer
 
 $settings
 

Private Attributes

 $eventHandler
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailMimeTransportBase::__construct ( ilSetting  $settings,
ilAppEventHandler  $eventHandler 
)

ilMailMimeTransportBase constructor.

Parameters
ilSetting$settings
ilAppEventHandler$eventHandler

Definition at line 26 of file class.ilMailMimeTransportBase.php.

27 {
28 $this->settings = $settings;
29 $this->eventHandler = $eventHandler;
30
31 $mail = new PHPMailer();
32 $this->setMailer($mail);
33 }
settings()
Definition: settings.php:2

References $eventHandler, $settings, setMailer(), and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ getMailer()

ilMailMimeTransportBase::getMailer ( )
protected
Returns
PHPMailer

Definition at line 38 of file class.ilMailMimeTransportBase.php.

38 : PHPMailer
39 {
40 return $this->mailer;
41 }

References $mailer.

Referenced by resetMailer(), and send().

+ Here is the caller graph for this function:

◆ onBeforeSend()

ilMailMimeTransportBase::onBeforeSend ( )
protected

Reimplemented in ilMailMimeTransportSmtp.

Definition at line 62 of file class.ilMailMimeTransportBase.php.

62 : void
63 {
64 }

Referenced by send().

+ Here is the caller graph for this function:

◆ resetMailer()

ilMailMimeTransportBase::resetMailer ( )
protected

Definition at line 51 of file class.ilMailMimeTransportBase.php.

51 : void
52 {
53 $this->getMailer()->clearAllRecipients();
54 $this->getMailer()->clearAttachments();
55 $this->getMailer()->clearReplyTos();
56 $this->getMailer()->ErrorInfo = '';
57 }

References getMailer().

Referenced by send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send()

ilMailMimeTransportBase::send ( ilMimeMail  $mail)
final

Parameters
ilMimeMail$mail
Returns
bool

Implements ilMailMimeTransport.

Definition at line 69 of file class.ilMailMimeTransportBase.php.

69 : bool
70 {
71 $this->resetMailer();
72
73 $this->getMailer()->XMailer = ' ';
74
75 foreach ($mail->getTo() as $recipients) {
76 $recipient_pieces = array_filter(array_map('trim', explode(',', $recipients)));
77 foreach ($recipient_pieces as $recipient) {
78 if (!$this->getMailer()->AddAddress($recipient, '')) {
79 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
80 }
81 }
82 }
83
84 foreach ($mail->getCc() as $carbon_copies) {
85 $cc_pieces = array_filter(array_map('trim', explode(',', $carbon_copies)));
86 foreach ($cc_pieces as $carbon_copy) {
87 if (!$this->getMailer()->AddCC($carbon_copy, '')) {
88 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
89 }
90 }
91 }
92
93 foreach ($mail->getBcc() as $blind_carbon_copies) {
94 $bcc_pieces = array_filter(array_map('trim', explode(',', $blind_carbon_copies)));
95 foreach ($bcc_pieces as $blind_carbon_copy) {
96 if (!$this->getMailer()->AddBCC($blind_carbon_copy, '')) {
97 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
98 }
99 }
100 }
101
102 $this->getMailer()->Subject = $mail->getSubject();
103
104 if ($mail->getFrom()->hasReplyToAddress()) {
105 if (!$this->getMailer()->addReplyTo($mail->getFrom()->getReplyToAddress(), $mail->getFrom()->getReplyToName())) {
106 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
107 }
108 }
109 if ($mail->getFrom()->hasEnvelopFromAddress()) {
110 $this->getMailer()->Sender = $mail->getFrom()->getEnvelopFromAddress();
111 }
112
113 if (!$this->getMailer()->setFrom($mail->getFrom()->getFromAddress(), $mail->getFrom()->getFromName(), false)) {
114 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
115 }
116
117 foreach ($mail->getAttachments() as $attachment) {
118 if (!$this->getMailer()->AddAttachment($attachment['path'], $attachment['name'])) {
119 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
120 }
121 }
122
123 foreach ($mail->getImages() as $image) {
124 if (!$this->getMailer()->AddEmbeddedImage($image['path'], $image['cid'], $image['name'])) {
125 ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
126 }
127 }
128
129 if ($mail->getFinalBodyAlt()) {
130 $this->getMailer()->IsHTML(true);
131 $this->getMailer()->AltBody = $mail->getFinalBodyAlt();
132 $this->getMailer()->Body = $mail->getFinalBody();
133 } else {
134 $this->getMailer()->IsHTML(false);
135 $this->getMailer()->AltBody = '';
136 $this->getMailer()->Body = $mail->getFinalBody();
137 }
138
139 ilLoggerFactory::getLogger('mail')->info(sprintf(
140 "Trying to delegate external email delivery:" .
141 " Initiated by: %s (%s) " .
142 "| To: %s | CC: %s | BCC: %s | Subject: %s " .
143 "| From: %s / %s " .
144 "| ReplyTo: %s / %s " .
145 "| EnvelopeFrom: %s",
146 $GLOBALS['DIC']->user()->getLogin(),
147 $GLOBALS['DIC']->user()->getId(),
148 implode(', ', $mail->getTo()),
149 implode(', ', $mail->getCc()),
150 implode(', ', $mail->getBcc()),
151 $mail->getSubject(),
152 $mail->getFrom()->getFromAddress(),
153 $mail->getFrom()->getFromName(),
154 $mail->getFrom()->getReplyToAddress(),
155 $mail->getFrom()->getReplyToName(),
156 $mail->getFrom()->getEnvelopFromAddress()
157 ));
158
159 ilLoggerFactory::getLogger('mail')->debug(sprintf("Mail Alternative Body: %s", $this->getMailer()->AltBody));
160 ilLoggerFactory::getLogger('mail')->debug(sprintf("Mail Body: %s", $this->getMailer()->Body));
161
162 $this->getMailer()->CharSet = 'utf-8';
163
164 $this->mailer->SMTPDebug = 4;
165 $this->mailer->Debugoutput = function ($message, $level) {
166 if (
167 strpos($message, 'Invalid address') !== false ||
168 strpos($message, 'Message body empty') !== false
169 ) {
170 ilLoggerFactory::getLogger('mail')->warning($message);
171 } else {
172 ilLoggerFactory::getLogger('mail')->debug($message);
173 }
174 };
175
176 $this->onBeforeSend();
177 $result = $this->getMailer()->Send();
178 if ($result) {
179 ilLoggerFactory::getLogger('mail')->info(sprintf(
180 'Successfully delegated external mail delivery'
181 ));
182
183 if (strlen($this->getMailer()->ErrorInfo) > 0) {
184 ilLoggerFactory::getLogger('mail')->warning(sprintf(
185 '... with most recent errors: %s',
186 $this->getMailer()->ErrorInfo
187 ));
188 }
189 } else {
190 ilLoggerFactory::getLogger('mail')->warning(sprintf(
191 'Could not deliver external email: %s',
192 $this->getMailer()->ErrorInfo
193 ));
194 }
195
196 $this->eventHandler->raise('Services/Mail', 'externalEmailDelegated', [
197 'mail' => $mail,
198 'result' => (bool) $result
199 ]);
200
201 return (bool) $result;
202 }
$result
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static getLogger($a_component_id)
Get component logger.
$message
Definition: xapiexit.php:14

References $GLOBALS, $message, $result, ilMimeMail\getAttachments(), ilMimeMail\getBcc(), ilMimeMail\getCc(), ilMimeMail\getFinalBody(), ilMimeMail\getFinalBodyAlt(), ilMimeMail\getFrom(), ilMimeMail\getImages(), ilLoggerFactory\getLogger(), getMailer(), ilMimeMail\getSubject(), ilMimeMail\getTo(), onBeforeSend(), resetMailer(), and user().

+ Here is the call graph for this function:

◆ setMailer()

ilMailMimeTransportBase::setMailer ( PHPMailer  $mailer)
protected
Parameters
PHPMailer$mailer

Definition at line 46 of file class.ilMailMimeTransportBase.php.

46 : void
47 {
48 $this->mailer = $mailer;
49 }

References $mailer.

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $eventHandler

ilMailMimeTransportBase::$eventHandler
private

Definition at line 19 of file class.ilMailMimeTransportBase.php.

Referenced by __construct().

◆ $mailer

ilMailMimeTransportBase::$mailer
protected

Definition at line 13 of file class.ilMailMimeTransportBase.php.

Referenced by getMailer(), and setMailer().

◆ $settings

ilSetting ilMailMimeTransportBase::$settings
protected

Definition at line 16 of file class.ilMailMimeTransportBase.php.

Referenced by __construct().


The documentation for this class was generated from the following file: