public function sendMail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             $setting = Setting::find()->where(['id' => 1])->one();
             $username = $setting->sendgridUsername;
             $password = $setting->sendgridPassword;
             $mail_admin = $setting->emailAdmin;
             $sendgrid = new \SendGrid($username, $password, array("turn_off_ssl_verification" => true));
             $email = new \SendGrid\Email();
             $mail = $user->email;
             //echo $user->email;exit(0);
             $resetLink = \Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
             $body_message = 'Hello ' . Html::encode($user->username) . ', <br>
             Follow the link below to reset your password:  <br>
             ' . Html::a(Html::encode($resetLink), $resetLink);
             $email->addTo($user->email)->setFrom($mail_admin)->setSubject('Password reset for ' . \Yii::$app->name)->setHtml($body_message);
             $response = $sendgrid->send($email);
             //print_r($response); exit(0);
             return $response;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 public function actionSendChat()
 {
     if (!empty($_POST)) {
         echo \sintret\chat\ChatRoom::sendChat($_POST);
         $message = Yii::$app->user->identity->username . ' : ' . $_POST['message'];
         $pos = strpos($message, "@");
         $setting = \app\models\Setting::findOne(1);
         if ($pos !== FALSE) {
             // $w = new WhatsApp($number, $app, $password);
             $usernameSendgrid = $setting->sendgridUsername;
             $passwordSendgrid = $setting->sendgridPassword;
             $users = \app\models\User::find()->where(['status' => \app\models\User::STATUS_ACTIVE])->all();
             foreach ($users as $model) {
                 $aprot = '@' . strtolower($model->username);
                 if (strpos($message, $aprot) !== false) {
                     $sendgrid = new \SendGrid($usernameSendgrid, $passwordSendgrid, array("turn_off_ssl_verification" => true));
                     $email = new \SendGrid\Email();
                     $email->addTo($model->email)->setFrom($setting->emailSupport)->setSubject('Chat from ' . $setting->applicationName)->setHtml($message);
                     $sendgrid->send($email);
                 } else {
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $from
  * @param string $to
  * @param string $message
  * @param string $subject
  *
  * @return \stdClass
  */
 protected function sendMail($from, $to, $message, $subject)
 {
     $sendGrind = new \SendGrid($this->username, $this->password);
     $email = new Email();
     $email->addTo($from)->addTo($to)->setSubject($subject)->setText(strip_tags($message))->setHtml($message);
     return $sendGrind->send($email);
 }
Ejemplo n.º 4
0
function sendEmail($to, $subject, $message)
{
    $sendgrid = new SendGrid('ilmarching_mail', 'aksld8jc98aisndcasd98ch98273hnd9das8ejncm');
    $email = new SendGrid\Email();
    $email->addTo($to)->setFrom('*****@*****.**')->setSubject($subject)->setText('text')->setHtml($message);
    $sendgrid->send($email);
}
Ejemplo n.º 5
0
function sendEmail($to, $subject, $message)
{
    $sendgrid = new SendGrid('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');
    $email = new SendGrid\Email();
    $email->addTo($to)->setFrom('*****@*****.**')->setSubject($subject)->setText('text')->setHtml($message);
    $sendgrid->send($email);
}
Ejemplo n.º 6
0
 public function sendEmail($mail)
 {
     $setting = Setting::find()->where(['id' => 1])->one();
     $username = $setting->sendgridUsername;
     $password = $setting->sendgridPassword;
     $mail_admin = $setting->emailAdmin;
     $sendgrid = new \SendGrid($username, $password, array("turn_off_ssl_verification" => true));
     $email = new \SendGrid\Email();
     $subject = 'Registrasi Berhasil';
     $body = 'Thanks ' . $this->username . ',';
     $body .= "\n";
     $body .= "Registrasi anda berhasil, kami akan segera mereview kembali registrasi anda. \n";
     $body .= "Thanks, \n";
     $body .= Yii::$app->name;
     $body_message = $this->template($subject, $body, $logo);
     $email->addTo($mail)->setFrom($mail_admin)->setSubject('Registrasi berhasil')->setHtml($body_message)->addCategory("registrasi");
     $response = $sendgrid->send($email);
     //return $response;
     //send whatsapp
     if ($setting->whatsappNumber && $setting->whatsappPassword) {
         $number = $setting->whatsappNumber;
         $app = Yii::$app->name;
         $password = $setting->whatsappPassword;
         $w = new WhatsApp($number, $app, $password);
         $w->send($setting->whatsappSend, $body);
     }
 }
Ejemplo n.º 7
0
 public function send(MessageInterface $message)
 {
     if (count($message->getToList()) === 0) {
         // TODO FIXED EXCEPTION
         throw new \Exception();
     }
     foreach ($message->getToList() as $email) {
         if (!$this->validateEmail($email)) {
             // TODO FIXED EXCEPTION
             throw new \Exception();
         }
     }
     $sendgrid = new \SendGrid(env("SENDGRID_USERNAME"), env("SENDGRID_PASSWORD"));
     $email = new \SendGrid\Email();
     $email->addTo($message->getToList())->setFrom($message->getFrom())->setSubject($message->getSubject())->setText($message->getTextBody())->setHtml($message->getHtmlBody());
     if (is_array($message->getBccList())) {
         $email->addBcc($message->getBccList());
     }
     $email->setAttachments($message->getAttachments());
     try {
         $sendgrid->send($email);
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * Override Email send
  *
  * @param   SendGrid\Email  $email      Email object with email info 
  * @param   SendGrid        $sendgrid   Sendgrid object with credentials info
  * @return  array                       Array of results
  */
 function wp_send(SendGrid\Email $email, $sendgrid)
 {
     $form = $email->toWebFormat();
     $form['api_user'] = Sendgrid_Tools::get_username();
     $form['api_key'] = Sendgrid_Tools::get_password();
     $url = $sendgrid->url . $sendgrid->endpoint;
     $files = preg_grep('/files/', array_keys($form));
     if (count($files) > 0) {
         if (in_array('curl', get_loaded_extensions())) {
             $response = $sendgrid->postRequest($sendgrid->endpoint, $form);
             $response = array('body' => $response->raw_body);
         } else {
             update_option('sendgrid_curl_option', 'disabled');
             foreach ($files as $key => $value) {
                 unset($form[$value]);
             }
             $data = array('body' => $form);
             $response = wp_remote_post($url, $data);
         }
     } else {
         $data = array('body' => $form);
         $response = wp_remote_post($url, $data);
     }
     return $response;
 }
Ejemplo n.º 9
0
 protected function sendEmail($to, $from, $body, $subject)
 {
     $sendgrid = new SendGrid('fake username2', 'fake password 2');
     $email = new SendGrid\Email($this->username, $this->password);
     $email->addTo($to)->setFrom($from)->setSubject($subject)->setText($body)->setHtml($body);
     return $sendgrid->send($email);
 }
Ejemplo n.º 10
0
 public function testSendResponseWithSslOptionFalse()
 {
     $sendgrid = new SendGrid("foo", "bar", array("switch_off_ssl_verification" => true));
     $email = new SendGrid\Email();
     $email->setFrom('*****@*****.**')->setSubject('foobar subject')->setText('foobar text')->addTo('*****@*****.**')->addAttachment('./text');
     $response = $sendgrid->send($email);
     $this->assertEquals("Bad username / password", $response->errors[0]);
 }
Ejemplo n.º 11
0
function send_email($to_address, $subject, $text, $hmtl)
{
    global $SENDGRID_USER, $SENDGRID_PASS;
    $sendgrid = new SendGrid($SENDGRID_USER, $SENDGRID_PASS);
    $email = new SendGrid\Email();
    $email->addTo($to_address)->setFrom('*****@*****.**')->setSubject($subject)->setText($text)->setHtml($html);
    $sendgrid->send($email);
}
Ejemplo n.º 12
0
 /**
  * Simple function to send and e-mail
  * @param string $dest Mail destination
  * @param string $title Mail title
  * @param string $body Mail body
  */
 public static function sendMail($dest, $title, $body)
 {
     require_once 'vendor/autoload.php';
     include 'values/mailCredentials.php';
     $sendgrid = new SendGrid($mail_user, $mail_password);
     $email = new SendGrid\Email();
     $email->addTo($dest)->setFrom('*****@*****.**')->setSubject($title)->setText($body);
     $response = $sendgrid->send($email);
     return $response->getCode() == 200;
 }
Ejemplo n.º 13
0
 /**
  * Sends an email using the Sendgrid Email API.
  *
  * @return void
  */
 protected function _sendWithSendgrid()
 {
     try {
         $sendgrid = new \SendGrid(Settings::config()->transport_token);
         $email = new \SendGrid\Email();
         $email->addTo($this->email)->setFrom(Settings::config()->transport_email)->setSubject($this->subject)->setHtml($this->message);
         $sendgrid->send($email);
     } catch (\SendGrid\Exception $e) {
         Debugger::log($e);
     }
 }
Ejemplo n.º 14
0
 public function send()
 {
     $config = \Drupal::config('spectrum.settings');
     $api_key = $config->get('sendgrid_api_key');
     if (!strlen($api_key)) {
         \Drupal::logger('spectrum')->error('Spectrum Error: API Key cannot be blank.');
         return NULL;
     }
     $this->email->setSubject($this->template->renderBlock('subject', $this->templateParameters));
     $this->email->setText($this->template->renderBlock('body_text', $this->templateParameters));
     $this->email->setHtml($this->template->renderBlock('body_html', $this->templateParameters));
     $sendgrid = new \SendGrid($api_key);
     $sendgrid->send($this->email);
 }
Ejemplo n.º 15
0
 static function sendEmail($to, $from, $subject, $message, $cc)
 {
     //User credentials
     $sendgrid_username = "******";
     $sendgrid_password = "******";
     //Set SendGrid Parameters
     $sendgrid = new SendGrid($sendgrid_username, $sendgrid_password, array("turn_off_ssl_verification" => true));
     //instantiate library class
     $email = new SendGrid\Email();
     //Set variables(to,cc,from,subject, message & headers for email) and send email
     $email->addTo($to)->addTo($cc)->setFrom($from)->setSubject($subject)->setCc($cc)->setHtml($message)->addHeader('X-Sent-Using', 'SendGrid-API')->addHeader('X-Transport', 'web');
     //Wait for email response
     $response = $sendgrid->send($email);
 }
Ejemplo n.º 16
0
 public function deliver($message)
 {
     $sendgrid = new \SendGrid($this->username, $this->password, $this->options);
     $email = new \SendGrid\Email();
     $to = $message->getTo();
     if (is_array($to)) {
         foreach ($to as $rcpt) {
             $email->addTo($rcpt);
         }
     } else {
         $email->addTo($to);
     }
     $email->setFrom($this->from)->setFromName($this->from_name)->setSubject($message->getSubject())->setText($message->renderText())->setHtml($message->renderHtml());
     $sendgrid->send($email);
 }
Ejemplo n.º 17
0
 protected function sendEmail($to, $subj, $text, $html = null)
 {
     $email = new \SendGrid\Email();
     $email->addCategory($subj);
     $email->addTo($to);
     $email->setFrom('*****@*****.**');
     $email->setFromName('Edge conf');
     $email->setSubject($subj);
     $email->setText($text);
     if ($html) {
         $emogrifier = new \Pelago\Emogrifier($html, file_get_contents(realpath(__DIR__ . '/../../../public/css/email.css')));
         $email->setHtml($emogrifier->emogrify());
     }
     $sendgrid = new \SendGrid($this->app->config->sendgrid->username, $this->app->config->sendgrid->password);
     $resp = $sendgrid->send($email);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     UserTestHelper::createBasicUser('billy');
     UserTestHelper::createBasicUser('jane');
     $someoneSuper = UserTestHelper::createBasicUser('someoneSuper');
     $group = Group::getByName('Super Administrators');
     $group->users->add($someoneSuper);
     $saved = $group->save();
     assert($saved);
     // Not Coding Standard
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     SendGrid::register_autoloader();
     Smtpapi::register_autoloader();
     if (SendGridTestHelper::isSetSendGridAccountTestConfiguration()) {
         Yii::app()->sendGridEmailHelper->apiUsername = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiUsername'];
         Yii::app()->sendGridEmailHelper->apiPassword = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiPassword'];
         Yii::app()->sendGridEmailHelper->setApiSettings();
         Yii::app()->sendGridEmailHelper->init();
         static::$testEmailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
     }
     // Delete item from jobQueue, that is created when new user is created
     Yii::app()->jobQueue->deleteAll();
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     self::$emailHelperSendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
     static::$userpsg = UserTestHelper::createBasicUser('userpsg');
     static::$usercstmsmtp = UserTestHelper::createBasicUser('usercstmsmtp');
     static::$basicuser = UserTestHelper::createBasicUser('basicuser');
     static::$bothSGandCstmUser = UserTestHelper::createBasicUser('bothSGandCstmUser');
     $someoneSuper = UserTestHelper::createBasicUser('someoneSuper');
     $group = Group::getByName('Super Administrators');
     $group->users->add($someoneSuper);
     $saved = $group->save();
     assert($saved);
     // Not Coding Standard
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         EmailMessageTestHelper::createEmailAccountForMailerFactory(static::$usercstmsmtp);
         EmailMessageTestHelper::createEmailAccountForMailerFactory(static::$bothSGandCstmUser);
     }
     SendGrid::register_autoloader();
     Smtpapi::register_autoloader();
     if (SendGridTestHelper::isSetSendGridAccountTestConfiguration()) {
         SendGridTestHelper::createSendGridEmailAccount(static::$userpsg);
         SendGridTestHelper::createSendGridEmailAccount(static::$bothSGandCstmUser);
         Yii::app()->sendGridEmailHelper->apiUsername = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiUsername'];
         Yii::app()->sendGridEmailHelper->apiPassword = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiPassword'];
         Yii::app()->sendGridEmailHelper->setApiSettings();
         Yii::app()->sendGridEmailHelper->init();
     }
     // Delete item from jobQueue, that is created when new user is created
     Yii::app()->jobQueue->deleteAll();
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
 {
     $sendgrid = new \SendGrid($this->key);
     $email = new \SendGrid\Email();
     list($from, $from_name) = $this->getFromAddresses($message);
     $email->setFrom($from);
     $email->setFromName($from_name);
     $email->setSubject($message->getSubject());
     $email->setHtml($message->getBody());
     $this->setTo($email, $message);
     $this->setCc($email, $message);
     $this->setBcc($email, $message);
     $this->setText($email, $message);
     $this->setAttachment($email, $message);
     $sendgrid->send($email);
     $this->deleteTempAttachments();
 }
Ejemplo n.º 21
0
 public function send()
 {
     $options = array('turn_off_ssl_verification' => true);
     $sendgrid = new \SendGrid($this->username, $this->password, $options);
     $email = new \SendGrid\Email();
     $email->addTo($this->to)->setFrom($this->from)->setSubject($this->subject)->setFromName($this->fromName)->setHtml($this->conteudo)->setCc($this->from)->addFilter('templates', 'enabled', 1)->addFilter('templates', 'template_id', $this->template);
     try {
         $sendgrid->send($email);
         return array('enviado' => true, 'mensagem' => 'Enviado com sucesso');
     } catch (\SendGrid\Exception $e) {
         $string = '';
         foreach ($e->getErrors() as $er) {
             $string .= $e->getCode() . ' - ' . $er . '<br/>';
         }
         return array('enviado' => false, 'mensagem' => $string);
     }
 }
 public function sendEmail(Email $email)
 {
     $apiKeys = env("SENDGRID_APIKEY");
     if (is_null($apiKeys)) {
         throw new SendgridServiceException();
     }
     if (!$email->getFrom()) {
         throw new SendgridServiceException();
     }
     $sendgrid = new \SendGrid($apiKeys);
     try {
         $sendgrid->send($email);
     } catch (\Exception $e) {
         var_dump($e->getMessage());
         throw new SendgridServiceException();
     }
 }
Ejemplo n.º 23
0
function sendgridEmail($name, $email_address, $phone, $message)
{
    $name = htmlspecialchars($name);
    $email_address = htmlspecialchars($email_address);
    $phone = htmlspecialchars($phone);
    $message = htmlspecialchars($message);
    $html = "<p>Salut <strong>BoostU</strong>!</p>\r\n            <p>Vous venez de recevoir un demande d'information:</p> <br>\r\n            <p><strong>Nom:</strong> " . $name . "</p>\r\n            <p><strong>Email:</strong> " . $email_address . "</p>\r\n            <p><strong>Numéro de téléphone:</strong> " . $phone . "</p>\r\n            <p><strong>Message:</strong><br>" . $message . "</p><br><br>\r\n            <p style='color: grey;'>Bonne journée !</p>";
    $sendgrid = new SendGrid('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');
    $email = new SendGrid\Email();
    $email->addSmtpapiTo('*****@*****.**')->setFrom('*****@*****.**')->setSubject('Contact information from landing page')->setText('Salut BoostU')->setHtml($html);
    // Or catch the error
    try {
        $sendgrid->send($email);
    } catch (\SendGrid\Exception $e) {
        echo $e->getCode();
        foreach ($e->getErrors() as $er) {
            echo $er;
        }
    }
}
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = $super;
     SendGrid::register_autoloader();
     Smtpapi::register_autoloader();
     if (SendGridTestHelper::isSetSendGridAccountTestConfiguration()) {
         static::$apiUsername = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiUsername'];
         static::$apiPassword = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiPassword'];
         static::$testEmailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
     }
 }
Ejemplo n.º 25
0
 protected function sendEmail($subject)
 {
     // If there is a message to send, send it
     if (!empty($this->message)) {
         self::printLog(' - Sending email');
         // Send email
         $sendgrid = new \SendGrid(SENDGRID_KEY);
         $email = new \SendGrid\Email();
         $email->addTo(TO_ADDRESS)->setFrom(FROM_ADDRESS)->setSubject($subject)->setHtml($this->message);
         try {
             $sendgrid->send($email);
             self::printLog('  - Email sent');
         } catch (\SendGrid\Exception $e) {
             self::printLog($e->getCode());
             foreach ($e->getErrors() as $er) {
                 self::printLog($er);
             }
         }
     } else {
         self::printLog(' - No email to send');
     }
 }
Ejemplo n.º 26
0
 /**
  * Controller made to launch temporary tests
  */
 public function tests()
 {
     echo 'tests';
     $f3 = \Base::instance();
     $sendgrid = new \SendGrid('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');
     $emails = explode("\n", file_get_contents('app/controllers/emails.txt'));
     //$emails = array('*****@*****.**', '*****@*****.**');
     foreach ($emails as $email) {
         $mail = new \SendGrid\Email();
         $mail->addTo($email)->setFrom('*****@*****.**')->setSubject('Lunch')->setHtml(\Template::instance()->render('mail.html'));
         try {
             $sendgrid->send($mail);
             echo "Mail to (sha1 of the email) " . sha1($email) . " sent !<br />\n";
         } catch (\SendGrid\Exception $e) {
             echo $e->getCode();
             foreach ($e->getErrors() as $er) {
                 echo $er;
             }
         }
     }
     /*$email = new \SendGrid\Email();
             $email
                 ->addTo('*****@*****.**')
                 ->setFrom('*****@*****.**')
                 ->setSubject('Subject goes here')
                 ->setText('Hello World!')
                 ->setHtml('<strong>Hello World!</strong>')
             ;
     
             try {
                 $sendgrid->send($email);
                 echo 'Mail sent !';
             } catch(\SendGrid\Exception $e) {
                 echo $e->getCode();
                 foreach($e->getErrors() as $er) {
                     echo $er;
                 }
             }*/
 }
Ejemplo n.º 27
0
function main($argc, $argv)
{
    // Reset to 0 upon success
    $rc = 1;
    // 3 args (+progname) required
    if ($argc != 4) {
        usage();
        printf("ERROR: 3 args required.\n");
    } else {
        // Store args
        $commandLine = new CommandLine_sgstats2phone($argc, $argv);
        // Extract args
        $commandLine->extractArgs();
        // Validate args
        if (($argStatus = $commandLine->validateArgs()) != 0) {
            usage();
            $commandLine->printArgErrorMessage($argStatus);
        } else {
            // Store the args in the sendGrid object
            $sendGrid = new SendGrid($commandLine->argPhone, $commandLine->argUser, $commandLine->argApiKey);
            // MySecretApiKey
            // Get the SendGrid stats for the current day (via REST/XML)
            if ($sendGrid->statsGet() != 0) {
                printf("ERROR: sendGrid->statsGet()\n");
            } else {
                // Assemble the text-to-speech text, setup params to pass to curl
                $sendGrid->assembleStats();
                // Send stats to phone
                if (SendGridCurl::issueRequest($sendGrid->get_statsParams()) == 0) {
                    // Successful
                    $rc = 0;
                }
            }
        }
    }
    exit($rc);
}
Ejemplo n.º 28
0
 /**
  * Send the mail.
  *
  * @param Midas_Mail $mail mail instance
  * @throws Midas_Service_SendGrid_Exception
  */
 public function sendMail(Midas_Mail $mail)
 {
     if (is_null($this->_client)) {
         $this->_client = new \SendGrid($this->_user, $this->_key, $this->_config);
     }
     $email = new \SendGrid\Email();
     $email->setBccs($mail->getBcc());
     $email->setCcs($mail->getCc());
     $email->setHtml($mail->getBodyHtml(true));
     $email->setFrom($mail->getFrom());
     $email->setReplyTo($mail->getReplyTo());
     $email->setSubject($mail->getSubject());
     $email->setText($mail->getBodyText(true));
     $email->setTos($mail->getTo());
     try {
         $this->_client->send($email);
     } catch (\SendGrid\Exception $exception) {
         throw new Midas_Service_SendGrid_Exception('Could not send mail');
     }
 }
Ejemplo n.º 29
0
 /**
  * @param string|null $subject
  * @param string|null $template
  * @return bool
  * @throws \SendGrid\Exception
  */
 public function send($subject = null, $template = null)
 {
     if (null !== $subject) {
         $this->setSubject($subject);
     }
     if (null !== $template) {
         $this->setTemplate($template);
     }
     $email = new \SendGrid\Email();
     $email->setFrom($this->fromEmail);
     $email->setFromName($this->fromName);
     $email->setSubject($this->subject);
     $email->setHtml(' ');
     $email->setTemplateId($this->template);
     foreach ($this->recipients as $recipient) {
         /**
          * SendGrid API library requires to use 'addSmtpapiTo' method in case of many recipients.
          * On the other side, it does not allow to mix Smtpapi methods with non-Smtpapi methods, therefore,
          * original methods 'addBcc' and 'addCc' cannot be used here.
          */
         $email->addSmtpapiTo($recipient->getEmail(), $recipient->getName());
     }
     $email->setSubstitutions($this->getLocalVariables());
     $email->setAttachments($this->attachments);
     $this->setSections($email);
     if (null !== $this->replyTo) {
         $email->setReplyTo($this->replyTo);
     }
     if (false === empty($this->headers)) {
         $email->setHeaders($this->headers);
     }
     try {
         $this->sendgrid->send($email);
         $this->cleanAttachments();
         return true;
     } catch (\SendGrid\Exception $e) {
         $this->cleanAttachments();
         throw $e;
     }
 }
Ejemplo n.º 30
0
 /**
  * Sends an email using the Sendgrid Email API.
  *
  * @return void
  */
 protected function _sendWithSendgrid()
 {
     /*
      * Decrypt Key Information
      */
     list($iv, $hash) = explode('.', Settings::config()->sendgrid_api_key);
     list($username, $password) = explode('|', Components\Authentication::decrypt($hash, $iv));
     $sendgrid = new \SendGrid($username, $password);
     $email = new \SendGrid\Email();
     $email->addTo($this->email)->setFrom(Settings::config()->sendmail_email)->setSubject($this->subject)->setHtml($this->message);
     $sendgrid->send($email);
 }