ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilMailMimeTransportBase Class Reference
+ Inheritance diagram for ilMailMimeTransportBase:
+ Collaboration diagram for ilMailMimeTransportBase:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

PHPMailer $mailer
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

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

References setMailer().

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

Member Function Documentation

◆ getMailer()

ilMailMimeTransportBase::getMailer ( )
protected

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

References $mailer.

Referenced by resetMailer(), and send().

33  : PHPMailer
34  {
35  return $this->mailer;
36  }
+ Here is the caller graph for this function:

◆ onBeforeSend()

ilMailMimeTransportBase::onBeforeSend ( )
protected

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

Referenced by send().

51  : void
52  {
53  }
+ Here is the caller graph for this function:

◆ resetMailer()

ilMailMimeTransportBase::resetMailer ( )
protected

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

References getMailer().

Referenced by send().

43  : void
44  {
45  $this->getMailer()->clearAllRecipients();
46  $this->getMailer()->clearAttachments();
47  $this->getMailer()->clearReplyTos();
48  $this->getMailer()->ErrorInfo = '';
49  }
+ 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 55 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().

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

◆ setMailer()

ilMailMimeTransportBase::setMailer ( PHPMailer  $mailer)
protected

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

References $mailer.

Referenced by __construct().

38  : void
39  {
40  $this->mailer = $mailer;
41  }
+ Here is the caller graph for this function:

Field Documentation

◆ $mailer

PHPMailer ilMailMimeTransportBase::$mailer
protected

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

Referenced by getMailer(), and setMailer().


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