Get the Encoder that provides Base64 encoding.
public static getBase64Encoding ( ) : Swift_Mime_ContentEncoder | ||
리턴 | Swift_Mime_ContentEncoder |
public function run($params = NULL) { $app_settings_model = new waAppSettingsModel(); $app_settings_model->set(array('blog', 'emailsubscription'), 'last_emailsubscription_cron_time', time()); $model = new blogEmailsubscriptionLogModel(); $row = $model->getByField('status', 0); if ($row) { $post_id = $row['post_id']; $post_model = new blogPostModel(); $post = $post_model->getById($post_id); $blog_model = new blogBlogModel(); $blog = $blog_model->getById($post['blog_id']); $subject = $blog['name'] . ': ' . $post['title']; $post_title = htmlspecialchars($post['title']); if ($blog['status'] == blogBlogModel::STATUS_PUBLIC) { $post_url = blogPost::getUrl($post); } else { $app_settings_model = new waAppSettingsModel(); $post_url = $app_settings_model->get(array('blog', 'emailsubscription'), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl()); $post_url .= "/blog/?module=post&id=" . $post_id; } $blog_name = htmlspecialchars($blog['name']); $body = '<html><body>' . sprintf(_wp("New post in the blog “%s”"), $blog_name) . ': <strong><a href="' . $post_url . '">' . $post_title . '</a></strong></body></html>'; $message = new waMailMessage(); $message->setEncoder(Swift_Encoding::getBase64Encoding()); $message->setSubject($subject); $message->setBody($body); $rows = $model->getByField(array('status' => 0, 'post_id' => $post_id), true); $message_count = 0; foreach ($rows as $row) { try { $message->setTo($row['email'], $row['name']); $status = $message->send() ? 1 : -1; $model->setStatus($row['id'], $status); if ($status) { $message_count++; } } catch (Exception $e) { $model->setStatus($row['id'], -1, $e->getMessage()); } } /** * Notify plugins about sending emailsubscripition * @event followup_send * @return void */ wa()->event('emailsubscription_send', $message_count); } }
/** * Invokes the HTML mailing class * Example for $mailconf. * * $mailconf = array( * 'plain' => Array ( * 'content'=> '' // plain content as string * ), * 'html' => Array ( * 'content'=> '', // html content as string * 'path' => '', * 'useHtml' => '' // is set mail is send as multipart * ), * 'defaultCharset' => 'utf-8', // your chartset * 'encoding' => '8-bit', // your encoding * 'attach' => Array (), // your attachment as array * 'alternateSubject' => '', // is subject empty will be ste alternateSubject * 'recipient' => '', // comma seperate list of recipient * 'recipient_copy' => '', // bcc * 'fromEmail' => '', // fromMail * 'fromName' => '', // fromName * 'replyTo' => '', // replyTo * 'priority' => '3', // priority of your Mail * 1 = highest, * 5 = lowest, * 3 = normal * ); * * @param array $mailconf Configuration for the mailerengine * * @return bool */ public static function sendMail(array $mailconf) { $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Utility/GeneralUtility', 'sendMail'); $additionalData = array(); if ($mailconf['additionalData']) { $additionalData = $mailconf['additionalData']; } foreach ($hooks as $hookObj) { // this is the current hook if (method_exists($hookObj, 'preProcessMail')) { $hookObj->preProcessMail($mailconf, $additionalData); } } foreach ($hooks as $hookObj) { if (method_exists($hookObj, 'ownMailRendering')) { return $hookObj->ownMailRendering($mailconf, $additionalData, $hooks); } } // validate e-mail addesses $mailconf['recipient'] = self::validEmailList($mailconf['recipient']); if ($mailconf['recipient']) { $parts = preg_split('/<title>|<\\/title>/i', $mailconf['html']['content'], 3); if (trim($parts[1])) { $subject = strip_tags(trim($parts[1])); } elseif ($mailconf['plain']['subject']) { $subject = $mailconf['plain']['subject']; } else { $subject = $mailconf['alternateSubject']; } /** * Mail message. * * @var \TYPO3\CMS\Core\Mail\MailMessage */ $message = CoreGeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); $message->setCharset($mailconf['defaultCharset']); if ($mailconf['encoding'] == 'base64') { $message->setEncoder(\Swift_Encoding::getBase64Encoding()); } elseif ($mailconf['encoding'] == '8bit') { $message->setEncoder(\Swift_Encoding::get8BitEncoding()); } $message->setSubject($subject); $message->setTo($mailconf['recipient']); $message->setFrom(self::validEmailList($mailconf['fromEmail']), implode(' ', CoreGeneralUtility::trimExplode(',', $mailconf['fromName']))); $replyAddress = $mailconf['replyTo'] ?: $mailconf['fromEmail']; $replyName = implode(' ', CoreGeneralUtility::trimExplode(',', $mailconf['replyTo'] ? '' : $mailconf['fromName'])); $message->setReplyTo($replyAddress, $replyName); if (isset($mailconf['recipient_copy']) && $mailconf['recipient_copy'] != '') { if ($mailconf['recipient_copy'] != '') { $message->setCc($mailconf['recipient_copy']); } } $message->setReturnPath($mailconf['fromEmail']); $message->setPriority((int) $mailconf['priority']); // add Html content if ($mailconf['html']['useHtml'] && trim($mailconf['html']['content'])) { $message->addPart($mailconf['html']['content'], 'text/html'); } // add plain text content $message->addPart($mailconf['plain']['content']); // add attachment if (is_array($mailconf['attach'])) { foreach ($mailconf['attach'] as $file) { if ($file && file_exists($file)) { $message->attach(\Swift_Attachment::fromPath($file)); } } } foreach ($hooks as $hookObj) { if (method_exists($hookObj, 'postProcessMail')) { $message = $hookObj->postProcessMail($message, $mailconf, $additionalData); } } return $message->send(); } return false; }
public function testGetBase64EncodingReturnsBase64Encoder() { $encoder = Swift_Encoding::getBase64Encoding(); $this->assertEqual('base64', $encoder->getName()); }
private function getEncoder(Email\Part $part) { $encoding = $part->getEncoding(); if (null === $encoding) { return null; } switch ($encoding) { case Email::ENCODING_BASE64: return \Swift_Encoding::getBase64Encoding(); case Email::ENCODING_QUOTED_PRINTABLE: return \Swift_Encoding::getQpEncoding(); case Email::ENCODING_8BIT: return \Swift_Encoding::get8BitEncoding(); case Email::ENCODING_7BIT: return \Swift_Encoding::get7BitEncoding(); case Email::ENCODING_RAW: return new \Swift_Mime_ContentEncoder_RawContentEncoder(); default: throw new \InvalidArgumentException('Unknown encoding "' . $encoding . '"'); } }
/** * Invokes the HTML mailing class * Example for $mailconf * * $mailconf = array( * 'plain' => Array ( * 'content'=> '' // plain content as string * ), * 'html' => Array ( * 'content'=> '', // html content as string * 'path' => '', * 'useHtml' => '' // is set mail is send as multipart * ), * 'defaultCharset' => 'utf-8', // your chartset * 'encoding' => '8-bit', // your encoding * 'attach' => Array (), // your attachment as array * 'alternateSubject' => '', // is subject empty will be ste alternateSubject * 'recipient' => '', // comma seperate list of recipient * 'recipient_copy' => '', // bcc * 'fromEmail' => '', // fromMail * 'fromName' => '', // fromName * 'replyTo' => '', // replyTo * 'priority' => '3', // priority of your Mail * 1 = highest, * 5 = lowest, * 3 = normal * ); * * @param array $mailconf Configuration for the mailerengine * * @return bool */ public static function sendMail(array $mailconf) { $hookObjectsArr = array(); if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_div.php']['sendMail'])) { \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/lib/class.tx_commerce_div.php\'][\'sendMail\'] is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Utility/GeneralUtility.php\'][\'sendMail\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/lib/class.tx_commerce_div.php']['sendMail'] as $classRef) { $hookObjectsArr[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Utility/GeneralUtility.php']['sendMail'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Utility/GeneralUtility.php']['sendMail'] as $classRef) { $hookObjectsArr[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); } } $additionalData = array(); if ($mailconf['additionalData']) { $additionalData = $mailconf['additionalData']; } foreach ($hookObjectsArr as $hookObj) { // this is the current hook if (method_exists($hookObj, 'preProcessMail')) { $hookObj->preProcessMail($mailconf, $additionalData); } } foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'ownMailRendering')) { return $hookObj->ownMailRendering($mailconf, $additionalData, $hookObjectsArr); } } // validate e-mail addesses $mailconf['recipient'] = self::validEmailList($mailconf['recipient']); if ($mailconf['recipient']) { $parts = preg_split('/<title>|<\\/title>/i', $mailconf['html']['content'], 3); if (trim($parts[1])) { $subject = strip_tags(trim($parts[1])); } elseif ($mailconf['plain']['subject']) { $subject = $mailconf['plain']['subject']; } else { $subject = $mailconf['alternateSubject']; } /** * Mail message * * @var \TYPO3\CMS\Core\Mail\MailMessage $message */ $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); $message->setCharset($mailconf['defaultCharset']); if ($mailconf['encoding'] == 'base64') { $message->setEncoder(Swift_Encoding::getBase64Encoding()); } elseif ($mailconf['encoding'] == '8bit') { $message->setEncoder(Swift_Encoding::get8BitEncoding()); } $message->setSubject($subject); $message->setTo($mailconf['recipient']); $message->setFrom(self::validEmailList($mailconf['fromEmail']), implode(' ', \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $mailconf['fromName']))); $replyAddress = $mailconf['replyTo'] ?: $mailconf['fromEmail']; $replyName = implode(' ', \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $mailconf['replyTo'] ? '' : $mailconf['fromName'])); $message->setReplyTo($replyAddress, $replyName); if (isset($mailconf['recipient_copy']) && $mailconf['recipient_copy'] != '') { if ($mailconf['recipient_copy'] != '') { $message->setCc($mailconf['recipient_copy']); } } $message->setReturnPath($mailconf['fromEmail']); $message->setPriority((int) $mailconf['priority']); // add Html content if ($mailconf['html']['useHtml'] && trim($mailconf['html']['content'])) { $message->addPart($mailconf['html']['content'], 'text/html'); } // add plain text content $message->addPart($mailconf['plain']['content']); // add attachment if (is_array($mailconf['attach'])) { foreach ($mailconf['attach'] as $file) { if ($file && file_exists($file)) { $message->attach(Swift_Attachment::fromPath($file)); } } } foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'postProcessMail')) { $message = $hookObj->postProcessMail($message, $mailconf, $additionalData); } } return $message->send(); } return FALSE; }
/** * Specifies the encoding scheme in the message. * * @param string $encoding * * @return $this * @throws SwiftMailerException */ public function setContentTransferEncoding($encoding) { switch ($encoding) { case '7bit': $encoder = \Swift_Encoding::get7BitEncoding(); break; case '8bit': $encoder = \Swift_Encoding::get8BitEncoding(); break; case 'base64': $encoder = \Swift_Encoding::getBase64Encoding(); break; case 'qp': $encoder = \Swift_Encoding::getQpEncoding(); break; default: throw new SwiftMailerException('Invalid encoding name provided. Valid encodings are [7bit, 8bit, base64, qp].'); break; } $this->message->setEncoder($encoder); return $this; }
$transport->setEncryption('tls'); # Create Mailer $mailer = Swift_Mailer::newInstance($transport); # DKIM if ($this->sub_dkim_active) { $privateKey = file_get_contents(LETHE_KEY_STORE . DIRECTORY_SEPARATOR . $this->sub_dkim_private); $domainName = $this->sub_dkim_domain; $selector = $this->sub_dkim_selector; $signer = new Swift_Signers_DKIMSigner($privateKey, $domainName, $selector); $message = Swift_SignedMessage::newInstance(); $message->attachSigner($signer); } else { $message = Swift_Message::newInstance(); } # Create a message $message->setEncoder(Swift_Encoding::getBase64Encoding()); $message->setReplyTo(array($this->sub_reply_mail => $this->sub_from_title)); $message->setCharset('utf-8'); $message->setPriority(3); $message->setFrom(array($this->sub_from_mail => $this->sub_from_title)); if ($this->sub_mail_attach != '') { $message->attach(Swift_Attachment::fromPath($this->sub_mail_attach)->setFilename(basename($this->sub_mail_attach))->setContentType('application/octet-stream')); } $headers = $message->getHeaders(); $headers->addTextHeader('X-Mailer', 'Lethe Newsletter v' . LETHE_VERSION . ' http://www.newslether.com/'); $headers->addTextHeader('X-Mailer', 'Powered by Artlantis Design Studio http://www.artlantis.net/'); $headers->addTextHeader('X-Lethe-ID', $this->sub_mail_id); $headers->addTextHeader('X-Lethe-Receiver', ''); # Receivers foreach ($this->sub_mail_receiver as $key => $value) { $message->setTo(array($key => $value['name']));
/** * Send of the email using php mail function. * * @var array $recipient: the recipient array. array($name => $mail) * @return boolean true if there is recipient and content, otherwise false */ function sendTheMail($recipient) { // $conf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail']; // init the swiftmailer object /** @var $mailer \TYPO3\CMS\Core\Mail\MailMessage */ $mailer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); $mailer->setFrom(array($this->from_email => $this->from_name)); $mailer->setSubject($this->subject); $mailer->setPriority($this->priority); if ($this->replyto_email) { $mailer->setReplyTo(array($this->replyto_email => $this->replyto_name)); } else { $mailer->setReplyTo(array($this->from_email => $this->from_name)); } //setting additional header // organization and TYPO3MID $header = $mailer->getHeaders(); $header->addTextHeader('X-TYPO3MID', $this->TYPO3MID); if ($this->organisation) { $header->addTextHeader('Organization', $this->organisation); } if (GeneralUtility::validEmail($this->dmailer['sys_dmail_rec']['return_path'])) { $mailer->setReturnPath($this->dmailer['sys_dmail_rec']['return_path']); } //set the recipient $mailer->setTo($recipient); // TODO: setContent should set the images (includeMedia) or add attachment $this->setContent($mailer); if ($this->encoding == 'base64') { $mailer->setEncoder(\Swift_Encoding::getBase64Encoding()); } if ($this->encoding == '8bit') { $mailer->setEncoder(\Swift_Encoding::get8BitEncoding()); } //TODO: do we really need the return value? $sent = $mailer->send(); $failed = $mailer->getFailedRecipients(); //unset the mailer object unset($mailer); // Delete temporary files // see setContent, where temp images are downloaded if (!empty($this->tempFileList)) { foreach ($this->tempFileList as $tempFile) { if (file_exists($tempFile)) { unlink($tempFile); } } } }
/** * Send of the email using php mail function. * * @param string/array $recipient The recipient array. array($name => $mail) * @param array $recipRow Recipient's data array * * @return void */ function sendTheMail($recipient, $recipRow = null) { // init the swiftmailer object /* @var $mailer \TYPO3\CMS\Core\Mail\MailMessage */ $mailer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage'); $mailer->setFrom(array($this->from_email => $this->from_name)); $mailer->setSubject($this->subject); $mailer->setPriority($this->priority); if ($this->replyto_email) { $mailer->setReplyTo(array($this->replyto_email => $this->replyto_name)); } else { $mailer->setReplyTo(array($this->from_email => $this->from_name)); } // setting additional header // organization and TYPO3MID $header = $mailer->getHeaders(); $header->addTextHeader('X-TYPO3MID', $this->TYPO3MID); if ($this->organisation) { $header->addTextHeader('Organization', $this->organisation); } // Hook to edit or add the mail headers if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/direct_mail']['res/scripts/class.dmailer.php']['mailHeadersHook'])) { $mailHeadersHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/direct_mail']['res/scripts/class.dmailer.php']['mailHeadersHook']; if (is_array($mailHeadersHook)) { $hookParameters = array('row' => &$recipRow, 'header' => &$header); $hookReference =& $this; foreach ($mailHeadersHook as $hookFunction) { GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookReference); } } } if (GeneralUtility::validEmail($this->dmailer['sys_dmail_rec']['return_path'])) { $mailer->setReturnPath($this->dmailer['sys_dmail_rec']['return_path']); } // set the recipient $mailer->setTo($recipient); // TODO: setContent should set the images (includeMedia) or add attachment $this->setContent($mailer); if ($this->encoding == 'base64') { $mailer->setEncoder(\Swift_Encoding::getBase64Encoding()); } if ($this->encoding == '8bit') { $mailer->setEncoder(\Swift_Encoding::get8BitEncoding()); } // TODO: do we really need the return value? $sent = $mailer->send(); $failed = $mailer->getFailedRecipients(); // unset the mailer object unset($mailer); // Delete temporary files // see setContent, where temp images are downloaded if (!empty($this->tempFileList)) { foreach ($this->tempFileList as $tempFile) { if (file_exists($tempFile)) { unlink($tempFile); } } } }
/** * onCreateNewQuestion * * @param QuestionAnswerEvent $event * * @return void */ public function onCreateNewQuestion(QuestionAnswerEvent $event) { $container = $this->getContainer(); $question = $event->getQuestion(); $token = $container->get('security.context')->getToken(); $service = $container->get('cekurte_google_api.gmail'); if ($service->getClient()->isAccessTokenExpired()) { $service->getClient()->refreshToken($token->getRefreshToken()); } try { $message = \Swift_Message::newInstance(); $message->addTo($container->getParameter('cekurte_zcpe_google_group_mail'))->addFrom($this->getUser()->getEmail())->setSubject($this->getSubject($question))->setBody($this->getTemplateBody($question), 'text/plain')->setEncoder(\Swift_Encoding::getBase64Encoding())->setCharset('utf-8'); $gmailMessage = new \Google_Service_Gmail_Message(); $gmailMessage->setRaw(base64_encode($message->toString())); $service->users_messages->send('me', $gmailMessage); $container->get('session')->getFlashBag()->add('message', array('type' => 'success', 'message' => $container->get('translator')->trans('The email has been sent successfully.'))); $question->setEmailHasSent(true); $em = $this->getContainer()->get('doctrine')->getManager(); $em->persist($question); $em->flush(); } catch (\Google_Service_Exception $e) { $container->get('session')->getFlashBag()->add('message', array('type' => 'error', 'message' => $e->getMessage())); } }