ILIAS  release_8 Revision v8.24
ilMailMimeTransportBase Class Reference

Class ilMailMimeTransportBase. More...

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

Public Member Functions

 __construct (ilSetting $settings, ilAppEventHandler $eventHandler)
 
 send (ilMimeMail $mail)
 
 send (ilMimeMail $mail)
 

Protected Member Functions

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

Protected Attributes

PHPMailer $mailer
 
ilSetting $settings
 

Private Attributes

ilAppEventHandler $eventHandler
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

33 {
34 $this->settings = $settings;
35 $this->eventHandler = $eventHandler;
36
37 $mail = new PHPMailer();
38 $this->setMailer($mail);
39 }

References $eventHandler, $settings, setMailer(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ getMailer()

ilMailMimeTransportBase::getMailer ( )
protected

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

41 : PHPMailer
42 {
43 return $this->mailer;
44 }

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 59 of file class.ilMailMimeTransportBase.php.

59 : void
60 {
61 }

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

Implements ilMailMimeTransport.

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

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

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

+ Here is the call graph for this function:

◆ setMailer()

ilMailMimeTransportBase::setMailer ( PHPMailer  $mailer)
protected

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

ilAppEventHandler ilMailMimeTransportBase::$eventHandler
private

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

Referenced by __construct().

◆ $mailer

PHPMailer ilMailMimeTransportBase::$mailer
protected

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

Referenced by getMailer(), and setMailer().

◆ $settings

ilSetting ilMailMimeTransportBase::$settings
protected

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

Referenced by __construct().


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