ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 

Protected Member Functions

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

Protected Attributes

 $mailer
 
 $settings
 

Private Attributes

 $eventHandler
 

Detailed Description

Class ilMailMimeTransportBase.

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

Constructor & Destructor Documentation

◆ __construct()

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

ilMailMimeTransportBase constructor.

Parameters
\ilSetting$settings
ilAppEventHandler$eventHandler

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

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

26  {
27  $this->settings = $settings;
28  $this->eventHandler = $eventHandler;
29 
30  $mail = new PHPMailer();
31  $this->setMailer($mail);
32  }
settings()
Definition: settings.php:2
PHPMailer - PHP email creation and transport class.
+ Here is the call graph for this function:

Member Function Documentation

◆ getMailer()

ilMailMimeTransportBase::getMailer ( )
protected
Returns
PHPMailer

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

References $mailer.

Referenced by resetMailer(), and send().

+ Here is the caller graph for this function:

◆ onBeforeSend()

ilMailMimeTransportBase::onBeforeSend ( )
protected

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

Referenced by send().

62  {
63  }
+ Here is the caller graph for this function:

◆ resetMailer()

ilMailMimeTransportBase::resetMailer ( )
protected

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

References getMailer().

Referenced by send().

51  {
52  $this->getMailer()->clearAllRecipients();
53  $this->getMailer()->clearAttachments();
54  $this->getMailer()->clearReplyTos();
55  $this->getMailer()->ErrorInfo = '';
56  }
+ 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 68 of file class.ilMailMimeTransportBase.php.

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

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

◆ setMailer()

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

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

References $mailer.

Referenced by __construct().

46  {
47  $this->mailer = $mailer;
48  }
+ Here is the caller graph for this function:

Field Documentation

◆ $eventHandler

ilMailMimeTransportBase::$eventHandler
private

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

Referenced by __construct().

◆ $mailer

ilMailMimeTransportBase::$mailer
protected

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

Referenced by getMailer(), and setMailer().

◆ $settings

ilMailMimeTransportBase::$settings
protected

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

Referenced by __construct().


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