ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailMimeTransportBase Class Reference

Class ilMailMimeTransportBase. More...

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

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

PHPMailer $mailer
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailMimeTransportBase::__construct ( protected ilSetting  $settings,
private readonly ilAppEventHandler  $eventHandler 
)

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

References setMailer().

31  {
32  $mail = new PHPMailer();
33  $this->setMailer($mail);
34  }
+ Here is the call graph for this function:

Member Function Documentation

◆ getMailer()

ilMailMimeTransportBase::getMailer ( )
protected

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

References $mailer.

Referenced by resetMailer(), and send().

36  : PHPMailer
37  {
38  return $this->mailer;
39  }
+ Here is the caller graph for this function:

◆ onBeforeSend()

ilMailMimeTransportBase::onBeforeSend ( )
protected

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

Referenced by send().

54  : void
55  {
56  }
+ Here is the caller graph for this function:

◆ resetMailer()

ilMailMimeTransportBase::resetMailer ( )
protected

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

References getMailer().

Referenced by send().

46  : void
47  {
48  $this->getMailer()->clearAllRecipients();
49  $this->getMailer()->clearAttachments();
50  $this->getMailer()->clearReplyTos();
51  $this->getMailer()->ErrorInfo = '';
52  }
+ 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 58 of file class.ilMailMimeTransportBase.php.

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().

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

◆ setMailer()

ilMailMimeTransportBase::setMailer ( PHPMailer  $mailer)
protected

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

References $mailer.

Referenced by __construct().

41  : void
42  {
43  $this->mailer = $mailer;
44  }
+ Here is the caller graph for this function:

Field Documentation

◆ $mailer

PHPMailer ilMailMimeTransportBase::$mailer
protected

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

Referenced by getMailer(), and setMailer().


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