public function sendMailConsumer(\PhpAmqpLib\Message\AMQPMessage $message) { $sendMail = json_decode($message->body); $latte = new Latte\Engine(); $sendMail->templateArr->email = $sendMail->to; $sendMail->templateArr->subject = $sendMail->subject; if (!is_null($sendMail->unsubscribeLink)) { $sendMail->templateArr->unsubscribeLink = $sendMail->unsubscribeLink; } $mail = new Nette\Mail\Message(); $mail->setFrom($sendMail->from)->addTo($sendMail->to)->setHtmlBody($latte->renderToString($this->config["appDir"] . $this->config['mailer']['templateDir'] . (is_null($sendMail->template) ? $this->config['mailer']['defaultTemplate'] : $sendMail->template), (array) $sendMail->templateArr)); if (!is_null($sendMail->unsubscribeEmail) || !is_null($sendMail->unsubscribeLink)) { $mail->setHeader('List-Unsubscribe', (!is_null($sendMail->unsubscribeEmail) ? '<mailto:' . $sendMail->unsubscribeEmail . '>' : '') . (!is_null($sendMail->unsubscribeEmail) && !is_null($sendMail->unsubscribeLink) ? ", " : "") . (!is_null($sendMail->unsubscribeLink) ? '<' . $sendMail->unsubscribeLink . '>' : ''), TRUE); } $mail->setSubject($sendMail->subject); try { $mailer = $this->emailFactory->getConnection($sendMail->connection); $mailer->send($mail); dump($sendMail->to); if ($sendMail->imapSave) { $this->saveToImap($mail->generateMessage(), is_null($sendMail->imapFolder) ? $this->config['imap']['sendFolder'] : $sendMail->imapFolder, $sendMail->imapConnection); } return TRUE; } catch (\Exception $e) { return FALSE; } }
public function __construct($templateDir, IMailer $mailer, ITemplateFactory $templateFactory, LinkGenerator $linkGenerator) { $this->mailer = $mailer; $this->templateDir = $templateDir; $this->templateFactory = $templateFactory; $this->linkGenerator = $linkGenerator; $message = new Nette\Mail\Message(); $message->setHeader('X-Mailer', NULL); // remove Nette Framework from header X-Mailer $this->message = $message; }
function send(Email $email) { $data = $email->get(); $mail = new Nette\Mail\Message(); $mail->setFrom($data->from, $data->fromName)->addReplyTo($data->replyTo, $data->replyToName)->addTo($data->to, $data->toName)->setHtmlBody($data->content); foreach ($data->attachments as $v) { call_user_func_array([$mail, 'addAttachment'], $v); } if (isset($data->unsubscribeEmail) || isset($data->unsubscribeLink)) { $mail->setHeader('List-Unsubscribe', (isset($data->unsubscribeEmail) ? '<mailto:' . $data->unsubscribeEmail . '>' : '') . (isset($data->unsubscribeEmail) && isset($data->unsubscribeLink) ? ", " : "") . (isset($data->unsubscribeLink) ? '<' . $data->unsubscribeLink . '>' : ''), TRUE); } $mail->setSubject($this->subjectPrefix . $data->subject); $this->mailer->send($mail); }
/** * Sends e-mail. * * Implementation of IMailer * @param Message The mail to send (instance of Nette\Message) * @return void * * @throws InvalidStateException if something went wrong */ function send(\Nette\Mail\Message $mail) { $from = $mail->getHeader('From'); //intentionally != $from = $from != NULL && !empty($from) ? array_keys($from) : NULL; if ($from !== NULL) { $this->client->setFrom($from[0]); } $to = $mail->getHeader('To'); $cc = $mail->getHeader('Cc'); $bcc = $mail->getHeader('Bcc'); $mail->setHeader('Bcc', NULL); $recipients = array(); //intentionally != $to != NULL && !empty($to) ? $recipients = array_merge($recipients, array_keys($to)) : NULL; $cc != NULL && !empty($cc) ? $recipients = array_merge($recipients, array_keys($cc)) : NULL; $bcc != NULL && !empty($bcc) ? $recipients = array_merge($recipients, array_keys($bcc)) : NULL; $this->client->setRecipients($recipients); $this->client->setBody($mail->generateMessage()); //throws InvalidStateException $this->client->send(); }