How to use getMailer method of mail class

Best Atoum code snippet using mail.getMailer

class.ilMailMimeTransportBase.php

Source:class.ilMailMimeTransportBase.php Github

copy

Full Screen

...26 }27 /**28 * @return PHPMailer29 */30 protected function getMailer() : PHPMailer31 {32 return $this->mailer;33 }34 /**35 * @param PHPMailer $mailer36 */37 protected function setMailer(PHPMailer $mailer) : void38 {39 $this->mailer = $mailer;40 }41 protected function resetMailer() : void42 {43 $this->getMailer()->clearAllRecipients();44 $this->getMailer()->clearAttachments();45 $this->getMailer()->clearReplyTos();46 $this->getMailer()->ErrorInfo = '';47 }48 /**49 *50 */51 protected function onBeforeSend() : void52 {53 }54 /**55 * @inheritdoc56 */57 final public function send(ilMimeMail $mail) : bool58 {59 $this->resetMailer();60 $this->getMailer()->XMailer = ' ';61 foreach ($mail->getTo() as $recipients) {62 $recipient_pieces = array_filter(array_map('trim', explode(',', $recipients)));63 foreach ($recipient_pieces as $recipient) {64 $this->getMailer()->AddAddress($recipient, '');65 }66 }67 foreach ($mail->getCc() as $carbon_copies) {68 $cc_pieces = array_filter(array_map('trim', explode(',', $carbon_copies)));69 foreach ($cc_pieces as $carbon_copy) {70 $this->getMailer()->AddCC($carbon_copy, '');71 }72 }73 foreach ($mail->getBcc() as $blind_carbon_copies) {74 $bcc_pieces = array_filter(array_map('trim', explode(',', $blind_carbon_copies)));75 foreach ($bcc_pieces as $blind_carbon_copy) {76 $this->getMailer()->AddBCC($blind_carbon_copy, '');77 }78 }79 $this->getMailer()->Subject = $mail->getSubject();80 if ($mail->getFrom()->hasReplyToAddress()) {81 $this->getMailer()->addReplyTo($mail->getFrom()->getReplyToAddress(), $mail->getFrom()->getReplyToName());82 }83 if ($mail->getFrom()->hasEnvelopFromAddress()) {84 $this->getMailer()->Sender = $mail->getFrom()->getEnvelopFromAddress();85 }86 $this->getMailer()->setFrom($mail->getFrom()->getFromAddress(), $mail->getFrom()->getFromName(), false);87 foreach ($mail->getAttachments() as $attachment) {88 $this->getMailer()->AddAttachment($attachment['path'], $attachment['name']);89 }90 foreach ($mail->getImages() as $image) {91 $this->getMailer()->AddEmbeddedImage($image['path'], $image['cid'], $image['name']);92 }93 if ($mail->getFinalBodyAlt()) {94 $this->getMailer()->IsHTML(true);95 $this->getMailer()->AltBody = $mail->getFinalBodyAlt();96 $this->getMailer()->Body = $mail->getFinalBody();97 } else {98 $this->getMailer()->IsHTML(false);99 $this->getMailer()->AltBody = '';100 $this->getMailer()->Body = $mail->getFinalBody();101 }102 ilLoggerFactory::getLogger('mail')->info(sprintf(103 "Trying to delegate external email delivery:" .104 " Initiated by: %s (%s) " .105 "| To: %s | CC: %s | BCC: %s | Subject: %s " .106 "| From: %s / %s " .107 "| ReplyTo: %s / %s " .108 "| EnvelopeFrom: %s",109 $GLOBALS['DIC']->user()->getLogin(),110 $GLOBALS['DIC']->user()->getId(),111 implode(', ', $mail->getTo()),112 implode(', ', $mail->getCc()),113 implode(', ', $mail->getBcc()),114 $mail->getSubject(),115 $mail->getFrom()->getFromAddress(),116 $mail->getFrom()->getFromName(),117 $mail->getFrom()->getReplyToAddress(),118 $mail->getFrom()->getReplyToName(),119 $mail->getFrom()->getEnvelopFromAddress()120 ));121 ilLoggerFactory::getLogger('mail')->debug(sprintf("Mail Alternative Body: %s", $this->getMailer()->AltBody));122 ilLoggerFactory::getLogger('mail')->debug(sprintf("Mail Body: %s", $this->getMailer()->Body));123 $this->getMailer()->CharSet = 'utf-8';124 $this->mailer->Debugoutput = function ($message, $level) {125 if (126 strpos($message, 'Invalid address') !== false ||127 strpos($message, 'Message body empty') !== false128 ) {129 ilLoggerFactory::getLogger('mail')->warning($message);130 } else {131 ilLoggerFactory::getLogger('mail')->debug($message);132 }133 };134 $this->onBeforeSend();135 $result = $this->getMailer()->Send();136 if ($result) {137 ilLoggerFactory::getLogger('mail')->info(sprintf(138 'Successfully delegated external mail delivery'139 ));140 if (strlen($this->getMailer()->ErrorInfo) > 0) {141 ilLoggerFactory::getLogger('mail')->warning(sprintf(142 '... with most recent errors: %s',143 $this->getMailer()->ErrorInfo144 ));145 }146 } else {147 ilLoggerFactory::getLogger('mail')->warning(sprintf(148 'Could not deliver external email: %s',149 $this->getMailer()->ErrorInfo150 ));151 }152 $this->eventHandler->raise('Services/Mail', 'externalEmailDelegated', [153 'mail' => $mail,154 'result' => (bool) $result155 ]);156 return (bool) $result;157 }158}...

Full Screen

Full Screen

Transport.php

Source:Transport.php Github

copy

Full Screen

...49 try {50 $this->setSmtpOptions();51 $this->setRecipients();52 $this->setContent();53 $this->getMailer()->send();54 if ($this->config->getDebugMode()) {55 $zendMailMessage = \Zend\Mail\Message::fromString($this->getMessage()->getRawMessage());56 $this->logger->log(Logger::DEBUG, __("Mail sent to %1 with subject %2", $zendMailMessage->getTo()->rewind()->getEmail(), $zendMailMessage->getSubject()));57 }58 } catch (Exception $e) {59 throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($this->getMailer()->ErrorInfo), $e);60 }61 }62 private function setSmtpOptions(): void63 {64 $this->getMailer()->isSMTP();65 $this->getMailer()->Host = $this->config->getHost();66 if ($this->config->getAuthType() === 'login') {67 $this->getMailer()->SMTPAuth = true;68 $this->getMailer()->Username = $this->config->getUsername();69 $this->getMailer()->Password = $this->config->getPassword();70 } else {71 $this->getMailer()->SMTPAuth = false;72 }73 $this->getMailer()->SMTPSecure = $this->config->getSecure();74 if (empty($this->config->getSecure())) {75 $this->getMailer()->SMTPAutoTLS = false;76 }77 $this->getMailer()->Port = $this->config->getPort();78 }79 public function setRecipients(): void80 {81 /** @var \Zend\Mail\Message $zendMailMessage */82 $zendMailMessage = \Zend\Mail\Message::fromString($this->getMessage()->getRawMessage());83 $recipient = $zendMailMessage->getFrom()->rewind();84 while ($recipient) {85 $this->getMailer()->setFrom($recipient->getEmail(), $recipient->getName());86 $recipient = $zendMailMessage->getFrom()->next();87 }88 $recipient = $zendMailMessage->getTo()->rewind();89 while ($recipient) {90 $this->getMailer()->addAddress($recipient->getEmail(), $recipient->getName());91 $recipient = $zendMailMessage->getTo()->next();92 }93 $recipient = $zendMailMessage->getReplyTo()->rewind();94 while ($recipient) {95 $this->getMailer()->addReplyTo($recipient->getEmail(), $recipient->getName());96 $recipient = $zendMailMessage->getReplyTo()->next();97 }98 $recipient = $zendMailMessage->getCc()->rewind();99 while ($recipient) {100 $this->getMailer()->addCC($recipient->getEmail(), $recipient->getName());101 $recipient = $zendMailMessage->getCc()->next();102 }103 $recipient = $zendMailMessage->getBCC()->rewind();104 while ($recipient) {105 $this->getMailer()->addBCC($recipient->getEmail(), $recipient->getName());106 $recipient = $zendMailMessage->getBCC()->next();107 }108 }109 public function setContent(): void110 {111 $this->getMailer()->isHTML(true);112 $this->getMailer()->Subject = $this->getMessage()->getSubject();113 $this->getMailer()->CharSet = PHPMailer::CHARSET_UTF8;114 $this->getMailer()->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;115 $body = $this->getMessage()->getBody();116 if ($body instanceof MimeMessageInterface || $body instanceof \Zend\Mime\Message) {117 /** @var MimePartInterface $part */118 $part = $body->getParts()[0];119 $this->getMailer()->Body = $part->getRawContent();120 $this->getMailer()->AltBody = strip_tags($part->getContent());121 } else if (is_string($body)) {122 /** @var string $body */123 $this->getMailer()->Body = strip_tags($body);124 $this->getMailer()->AltBody = strip_tags($body);125 } else {126 throw new \Exception("Body mail unrecognized");127 }128 }129 public function getMailer(): \PHPMailer\PHPMailer\PHPMailer130 {131 if (!$this->mailer) {132 $this->mailer = new PHPMailer(true);133 }134 return $this->mailer;135 }136 /**137 * @inheritdoc138 */139 public function getMessage(): \Magento\Framework\Mail\EMailMessageInterface140 {141 return $this->message;142 }143}...

Full Screen

Full Screen

getMailer

Using AI Code Generation

copy

Full Screen

1$obj = new Mail;2$obj->getMailer();3$obj = new Mail;4$obj->getMailer();5$obj = new Mail;6$obj->getMailer();7$obj = new Mail;8$obj->getMailer();9$obj = new Mail;10$obj->getMailer();11$obj = new Mail;12$obj->getMailer();13$obj = new Mail;14$obj->getMailer();15$obj = new Mail;16$obj->getMailer();17$obj = new Mail;18$obj->getMailer();19$obj = new Mail;20$obj->getMailer();21$obj = new Mail;22$obj->getMailer();23$obj = new Mail;24$obj->getMailer();25$obj = new Mail;26$obj->getMailer();27$obj = new Mail;28$obj->getMailer();29$obj = new Mail;30$obj->getMailer();31$obj = new Mail;32$obj->getMailer();33$obj = new Mail;34$obj->getMailer();35$obj = new Mail;36$obj->getMailer();

Full Screen

Full Screen

getMailer

Using AI Code Generation

copy

Full Screen

1require_once('mail.class.php');2$mail = new PHPMailer();3$mail->IsSMTP();4$mail->SMTPAuth = true;5$mail->SMTPSecure = 'ssl';6$mail->Host = 'smtp.gmail.com';7$mail->Port = 465;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger getMailer code on LambdaTest Cloud Grid

Execute automation tests with getMailer on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful