Ejemplo n.º 1
0
 /**
  * Send email via SNS
  * @param CakeEmail $email
  * @return bool
  */
 public function send(CakeEmail $email)
 {
     $ses = SesClient::factory(array("key" => "AKIAIQHPCMQTEEXD5MGA", "secret" => "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", 'region' => 'us-east-1'));
     $destination = array('ToAddresses' => array());
     foreach ($email->to() as $addr => $name) {
         $destination['ToAddresses'][] = "{$name} <{$addr}>";
     }
     foreach ($email->bcc() as $addr => $name) {
         $destination['BccAddresses'][] = "{$name} <{$addr}>";
     }
     $message = array('Subject' => array('Data' => $email->subject()), 'Body' => array());
     $text = $email->message('text');
     if (!empty($text)) {
         $message['Body']['Text'] = array('Data' => $text);
     }
     $html = $email->message('html');
     if (!empty($html)) {
         $message['Body']['Html'] = array('Data' => $html);
     }
     $from = '';
     foreach ($email->from() as $addr => $name) {
         $from = "{$name} <{$addr}>";
         break;
     }
     $response = $ses->sendEmail(['Source' => $from, 'Destination' => $destination, 'Message' => $message]);
     return !empty($response);
 }
Ejemplo n.º 2
0
 /**
  * @covers Aws\Ses\SesClient::factory
  */
 public function testFactoryInitializesClient()
 {
     $client = SesClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-east-1'));
     $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV4', $client->getSignature());
     $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials());
     $this->assertEquals('https://email.us-east-1.amazonaws.com', $client->getBaseUrl());
 }
Ejemplo n.º 3
0
 public function send($view, array $data, $callback)
 {
     $message = new Message(new Swift_Message());
     if ($callback instanceof Closure) {
         // callback must assign $to and $subject, deal with it
         call_user_func($callback, $message);
     } else {
         throw new InvalidArgumentException('Callback is not valid.');
     }
     $m = $message->getSwiftMessage();
     $filteredTo = array_filter(array_keys($message->getTo()), function ($email) {
         $skip = DB::table('ses_feedback')->where('email', $email)->first();
         if ($skip) {
             Log::info("skipping email:{$email}");
         }
         return !$skip;
     });
     if ($filteredTo) {
         $converter = new CssToInlineStyles();
         $converter->setEncoding($message->getCharset());
         $converter->setStripOriginalStyleTags();
         $converter->setUseInlineStylesBlock();
         $converter->setExcludeMediaQueries(false);
         $converter->setCleanup();
         $converter->setHTML(View::make($view, $data)->render());
         $body = $converter->convert();
         $config = Config::get('services.amazon');
         SesClient::factory($config)->sendEmail(array('Source' => $config['from'], 'Destination' => array('ToAddresses' => $filteredTo), 'Message' => array('Subject' => array('Data' => $m->getSubject(), 'Charset' => 'UTF-8'), 'Body' => array('Text' => array('Data' => strip_tags(str_replace("<br/>", "\n", $body)), 'Charset' => 'UTF-8'), 'Html' => array('Data' => $body, 'Charset' => 'UTF-8'))), 'ReplyToAddresses' => array()));
     }
 }
Ejemplo n.º 4
0
 public function __construct($settings)
 {
     parent::__construct($settings);
     $arr = array('key' => $this->settings->getSetting('Email: Amazon Access Key ID'), 'secret' => $this->settings->getSetting('Email: Amazon Secret Access Key'), 'region' => AWS_REGION);
     //$this->ses = new AmazonSES($arr);
     $this->ses = SesClient::factory($arr);
 }
 function send($options)
 {
     if (empty($options['fromEmail'])) {
         $return['success'] = false;
         $return['error_message'] = 'Must set a valid fromEmail!';
         return $return;
     }
     $client = SesClient::factory(array('version' => '2010-12-01', 'region' => AWS_REGION, 'credentials' => array('key' => AWS_KEY, 'secret' => AWS_SECRET)));
     // $options = array(
     // 	'fromName' = '', // string
     // 	'fromEmail' = '', // string
     // 	'replyToEmail' = '', // string
     // 	'toEmail' = array(), // array
     // 	'ccEmail' = array(), // array
     // 	'bccEmail' = array(), // array
     // 	'subject' = '', // string
     // 	'body_text' = '', // string
     // 	'body_html' = '', // string
     // );
     $msg = array();
     $msg['Source'] = '';
     if (!empty($options['fromName'])) {
         $msg['Source'] = $options['fromName'];
     }
     $msg['Source'] = $msg['Source'] . ' <' . $options['fromEmail'] . '>';
     if (is_array($options['replyToEmail']) && !empty($options['replyToEmail'])) {
         $msg['ReplyToAddresses'] = $options['replyToEmail'];
     }
     if (ENV_MODE == 'production') {
         if (is_array($options['toEmail']) && !empty($options['toEmail'])) {
             $msg['Destination']['ToAddresses'] = $options['toEmail'];
         }
         if (is_array($options['ccEmail']) && !empty($options['ccEmail'])) {
             $msg['Destination']['CcAddresses'] = $options['ccEmail'];
         }
         if (is_array($options['bccEmail']) && !empty($options['bccEmail'])) {
             $msg['Destination']['BccAddresses'] = $options['bccEmail'];
         }
     } else {
         $msg['Destination']['ToAddresses'][] = array(TEST_EMAIL_RECIPIENT);
     }
     $msg['Message']['Subject']['Data'] = $options['subject'];
     $msg['Message']['Subject']['Charset'] = "UTF-8";
     $msg['Message']['Body']['Text']['Data'] = $options['body_text'];
     $msg['Message']['Body']['Text']['Charset'] = "UTF-8";
     $msg['Message']['Body']['Html']['Data'] = $options['body_html'];
     $msg['Message']['Body']['Html']['Charset'] = "UTF-8";
     try {
         $result = $this->client->sendEmail($msg);
         // save the MessageId which can be used to track the request
         $return['success'] = true;
         $return['message_id'] = $result->get('MessageId');
     } catch (Exception $e) {
         // An error happened and the email did not get sent
         $return['success'] = false;
         $return['error_message'] = $e->getMessage();
     }
     return $return;
 }
Ejemplo n.º 6
0
 public function send(MailTypeInterface $mail = null)
 {
     $this->client = SesClient::factory(array('credentials' => array('key' => 'AKIAJMJVISA25SNTXASA', 'secret' => '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'), 'region' => 'eu-west-1'));
     if ($mail !== null) {
         $result = $this->client->sendEmail(array('Source' => 'The Mill <*****@*****.**>', 'ReplyToAddresses' => array('*****@*****.**'), 'SourceArn' => "arn:aws:ses:eu-west-1:511531539329:identity/themill.com", 'ReturnPathArn' => "arn:aws:ses:eu-west-1:511531539329:identity/themill.com", 'FromArn' => "arn:aws:ses:eu-west-1:511531539329:identity/themill.com", 'Destination' => array('ToAddresses' => array($mail->getEmailAddress())), 'Message' => array('Subject' => array('Data' => $mail->getSubject()), 'Body' => array('Text' => array('Data' => $this->getBodyHeader() . $mail->getBody() . $this->getBodyFooter()), 'Html' => array('Data' => $this->getBodyHeader() . $mail->getBody() . $this->getBodyFooter())))));
         return $result;
     }
     return false;
 }
Ejemplo n.º 7
0
function awsautoses_sesclient()
{
    static $client = null;
    if (!isset($client)) {
        $instanceDocument = awsautoses_get_instance_document();
        if ($instanceDocument && isset($instanceDocument->region)) {
            $client = SesClient::factory(array('region' => $instanceDocument->region, 'version' => '2010-12-01'));
        }
    }
    return $client;
}
Ejemplo n.º 8
0
 /**
  *
  * @param MessageInterface $message
  * @param array $config
  * @ param \Magento\Framework\ObjectManagerInterface $objectManager
  * @param SesClient $client
  * @throws \InvalidArgumentException
  */
 public function __construct(MessageInterface $message, array $config)
 {
     $this->message = $this->convertMailMessage($message);
     $credentials = new Credentials($config['user'], $config['password']);
     $client = SesClient::factory(array('credentials' => $credentials, 'region' => 'us-east-1', 'version' => '2010-12-01', 'timeout' => 10));
     $service = new SesService($client);
     // \Zend_Debug::dump(get_class_methods($service));
     // \Zend_Debug::dump($service->getSendQuota());
     // \Zend_Debug::dump($service->getSendStatistics());
     // // die;
     $this->transport = new HttpTransport($service);
 }
Ejemplo n.º 9
0
 /**
  * ses://accessid:aswsecret@region
  *
  * @param MailConnection $this->connection
  * @param Envelope $envelope
  */
 public function send(Envelope $envelope)
 {
     $mail = $this->prepareMailer($envelope);
     // Call the preSend to set all PHPMailer variables and get the correct header and body;
     $message = $mail->getFullMessageEnvelope();
     // Fix BCC header because PHPMailer does not send to us
     foreach ((array) $envelope->getBCC() as $bccEmail) {
         $message = 'Bcc: ' . $bccEmail . "\n" . $message;
     }
     //Send the message (which must be base 64 encoded):
     $ses = SesClient::factory(['credentials' => new Credentials($this->connection->getUsername(), $this->connection->getPassword()), 'region' => $this->connection->getServer()]);
     $ses->sendRawEmail(['RawMessage' => ['Data' => base64_encode($message)]]);
 }
Ejemplo n.º 10
0
 public function deliver($message, array $options = array())
 {
     $credentials = new Credentials($message->access_key_id, $message->access_key_secret);
     $client = SesClient::factory(array('credentials' => $credentials, 'region' => 'eu-west-1'));
     $body = array();
     if ($text = $message->body('text')) {
         $body['Text'] = array('Data' => $text, 'Charset' => $message->charset);
     }
     if ($html = $message->body('html')) {
         $body['Html'] = array('Data' => $html, 'Charset' => $message->charset);
     }
     $data = array('Source' => $message->from, 'Destination' => array('ToAddresses' => array($message->to)), 'Message' => array('Subject' => array('Data' => $message->subject, 'Charset' => $message->charset), 'Body' => $body));
     try {
         $client->sendEmail($data);
     } catch (\MessageRejectedException $e) {
         error_log($e->getMessage());
         return 'rejected';
     } catch (\Exception $e) {
         error_log($e->getMessage());
         return false;
     }
     return 'delivered';
 }
Ejemplo n.º 11
0
function emailSES($NomCuenta, $email, $asunto, $body, $filenamePDF, $content)
{
    require_once 'api/vendor/autoload.php';
    $ses = \Aws\Ses\SesClient::factory(array('key' => AWS_ACCES_KEY, 'secret' => AWS_SECRET_KEY, 'region' => 'us-west-2'));
    if (empty($content) || empty($filenamePDF)) {
        $emailadjunto = "--";
    } else {
        $emailadjunto = "\nContent-Type: application/octet-stream;\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment; filename=\"{$filenamePDF}\"\n\n{$content}\n\n--NextPart--";
    }
    $data = "From: OWLGROUP <*****@*****.**>\nTo: {$NomCuenta} <{$email}>\nSubject:{$asunto}\nMIME-Version: 1.0\nContent-type: Multipart/Mixed; boundary=\"NextPart\"\n\n--NextPart\nContent-Type: text/html;charset=UTF-8\n\n{$body}\n\n--NextPart{$emailadjunto}";
    $result = $ses->sendRawEmail(array('RawMessage' => array('Data' => base64_encode("{$data}")), 'Destinations' => array("{$NomCuenta} <{$email}>"), 'Source' => '*****@*****.**'));
}
Ejemplo n.º 12
0
 /**
  * コンストラクタ
  *
  * @return void
  **/
 public function __construct()
 {
     parent::__construct();
     $this->client = SesClient::factory($this->getConfig(Region::US_EAST_1));
 }
Ejemplo n.º 13
0
 public function __construct()
 {
     parent::__construct();
     $this->client = SesClient::factory($this->arrayconn);
 }
Ejemplo n.º 14
0
 /**
  * コンストラクタ
  * 
  * @param $key        	
  * @param $secret        	
  */
 public function __construct($key, $secret)
 {
     $sesClient = SesClient::factory(array('key' => $key, 'secret' => $secret, 'region' => Region::US_EAST_1));
     $this->_client = $sesClient;
 }
Ejemplo n.º 15
0
 /**
  * @return SesClient
  */
 public function getSesClient()
 {
     return SesClient::factory($this->awsApiKeyConfig);
 }
Ejemplo n.º 16
0
            } else {
                // The token is invalid and has probably been tampered with
                $app->response->setBody(json_encode(array('token' => 'InvalidToken')));
            }
        }
    } else {
        // User didn't supply a token to be refreshed so this is either an invalid request or
        // they just opened the appication.
        $app->response->setBody(json_encode(array('token' => 'InvalidToken')));
    }
});
$app->post('/api/login', function () use($app) {
    $app->response->headers->set('Content-Type', 'application/json');
    $email = $app->request->post('email');
    // Establish AWS Clients
    $sesClient = SesClient::factory(array('region' => 'us-west-2'));
    $tokenId = Helper::GUID();
    $msg = array();
    $msg['Source'] = '"Notello"<*****@*****.**>';
    //ToAddresses must be an array
    $msg['Destination']['ToAddresses'][] = $email;
    $msg['Message']['Subject']['Data'] = "Notello login email";
    $msg['Message']['Subject']['Charset'] = "UTF-8";
    $msg['Message']['Body']['Text']['Data'] = getLoginTextEmail($email, $tokenId);
    $msg['Message']['Body']['Text']['Charset'] = "UTF-8";
    $msg['Message']['Body']['Html']['Data'] = getLoginHTMLEmail($email, $tokenId);
    $msg['Message']['Body']['Html']['Charset'] = "UTF-8";
    try {
        $result = $sesClient->sendEmail($msg);
        //save the MessageId which can be used to track the request
        $msg_id = $result->get('MessageId');
Ejemplo n.º 17
0
 public function sesapi()
 {
     $to = isAke($this, 'to', false);
     if ($to) {
         $from = isAke($this, 'from', '*****@*****.**');
         $reply = isAke($this, 'reply', $from);
         $return = isAke($this, 'return', $reply);
         $fromName = isAke($this, 'from_name', 'clippCity');
         $subject = isAke($this, 'subject', 'Message');
         $priority = isAke($this, 'priority', 3);
         $files = isAke($this, 'files', []);
         $embeds = isAke($this, 'embeds', []);
         $text = isAke($this, 'text', false);
         $html = isAke($this, 'html', false);
         $client = SesClient::factory(array('key' => Config::get('aws.access_key'), 'secret' => Config::get('aws.secret_key'), 'version' => Config::get('aws.ses_version', '2010-12-01'), 'region' => Config::get('aws.host')));
         $body = [];
         if ($text) {
             $body['Text'] = ['Data' => $text, 'Charset' => 'UTF-8'];
         }
         if ($html) {
             $body['Html'] = ['Data' => $html, 'Charset' => 'UTF-8'];
         }
         $status = $client->sendEmail(['Source' => $from, 'Destination' => ['ToAddresses' => [$to]], 'Message' => ['Subject' => ['Data' => $subject, 'Charset' => 'UTF-8'], 'Body' => $body], 'ReplyToAddresses' => [$reply], 'ReturnPath' => $return]);
         return true;
     }
     return false;
 }
Ejemplo n.º 18
0
 public function __construct($config)
 {
     $this->client = SesClient::factory($config);
     parent::__construct();
 }
Ejemplo n.º 19
0
 /**
  * Create an instance of the Amazon SES Swift Transport driver.
  *
  * @return \Swift_SendmailTransport
  */
 protected function createSesDriver()
 {
     $sesClient = SesClient::factory($this->app['config']->get('services.ses', []));
     return new SesTransport($sesClient);
 }
Ejemplo n.º 20
0
 public function mail()
 {
     $client = SesClient::factory(array('key' => 'AKIAJ3WC7JCITHUWBVHQ', 'secret' => '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', 'version' => '2010-12-01', 'region' => 'eu-west-1'));
     $status = $client->sendEmail(array('Source' => '*****@*****.**', 'Destination' => array('ToAddresses' => array('*****@*****.**')), 'Message' => array('Subject' => array('Data' => 'SES Testing 2', 'Charset' => 'UTF-8'), 'Body' => array('Text' => array('Data' => 'My plain text email', 'Charset' => 'UTF-8'), 'Html' => array('Data' => '<b>My HTML Email</b>', 'Charset' => 'UTF-8'))), 'ReplyToAddresses' => array('*****@*****.**'), 'ReturnPath' => '*****@*****.**'));
     return true;
 }
Ejemplo n.º 21
0
 public function __construct(array $config)
 {
     $this->client = SesClient::factory((array) $config);
 }
Ejemplo n.º 22
0
 /**
  * Realiza el envio masivo a participantees o cofinanciadores
  * 
  * @param type $option 'messegers' || 'rewards'
  * @param type $project Instancia del proyecto de trabajo
  * @return boolean
  */
 public static function process_mailing($option, $project)
 {
     $who = array();
     // verificar que hay mensaje
     if (empty($_POST['message'])) {
         Message::Error(Text::get('dashboard-investors-mail-text-required'));
         return false;
     } else {
         $msg_content = nl2br(\strip_tags($_POST['message']));
     }
     // si a todos los participantes
     if ($option == 'messegers' && !empty($_POST['msg_all'])) {
         // a todos los participantes(if all investors)
         foreach (Model\Message::getMessegers($project->id) as $messeger => $msgData) {
             if ($messeger == $project->owner) {
                 continue;
             }
             $who[$messeger] = $messeger;
             //unset($msgData); // los datos del mensaje del participante no se usan
         }
     } elseif ($option == 'rewards' && !empty($_POST['msg_all'])) {
         // a todos los cofinanciadores
         foreach (Model\Invest::investors($project->id, false, true) as $user => $investor) {
             // no duplicar
             $who[$investor->user] = $investor->user;
         }
     } elseif (!empty($_POST['msg_user'])) {
         // a usuario individual
         $who[$_POST['msg_user']] = $_POST['msg_user'];
     } elseif ($option == 'rewards') {
         $msg_rewards = array();
         // estos son msg_reward-[rewardId], a un grupo de recompensa
         foreach ($_POST as $key => $value) {
             $parts = explode('-', $key);
             if ($parts[0] == 'msg_reward' && $value == 1) {
                 $msg_rewards[] = $parts[1];
             }
         }
         // para cada recompensa
         foreach ($msg_rewards as $reward) {
             foreach (Model\Invest::choosed($reward) as $user) {
                 $who[$user] = $user;
             }
         }
     }
     // no hay destinatarios
     if (count($who) == 0) {
         Message::Error(Text::get('dashboard-investors-mail-nowho'));
         return false;
     }
     // obtener contenido
     // segun destinatarios
     $allsome = explode('/', Text::get('regular-allsome'));
     $enviandoa = !empty($_POST['msg_all']) ? $allsome[0] : $allsome[1];
     if ($option == 'messegers') {
         Message::Info(Text::get('dashboard-messegers-mail-sendto', $enviandoa));
     } else {
         Message::Info(Text::get('dashboard-investors-mail-sendto', $enviandoa));
     }
     // Obtenemos la plantilla para asunto y contenido
     $template = Template::get(2);
     // Sustituimos los datos
     if (!empty($_POST['subject'])) {
         $subject = $_POST['subject'];
     } else {
         $subject = str_replace('%PROJECTNAME%', $project->name, $template->title);
     }
     $remite = $project->name . ' ' . Text::get('regular-from') . ' ';
     $remite .= NODE_ID != GOTEO_NODE ? NODE_NAME : GOTEO_MAIL_NAME;
     // para usar el proceso Sender:
     // - $who debe ser compatible con el formato $receivers
     // (falta nombre e email), sacarlo con getMini
     $receivers = array();
     foreach ($who as $userId) {
         $user = Model\User::getMini($userId);
         $user->user = $user->id;
         $receivers[] = $user;
     }
     //mailing use aws ses
     require 'library/aws/aws-autoloader.php';
     try {
         $sesClient = SesClient::factory(array('key' => AWS_SES_ACCESS, 'secret' => AWS_SES_SECERET, 'region' => \Aws\Common\Enum\Region::OREGON));
     } catch (SesException $exc) {
         die($exc->getMessage());
     }
     foreach ($receivers as $value) {
         $search = array('%MESSAGE%', '%PROJECTNAME%', '%PROJECTURL%', '%OWNERURL%', '%OWNERNAME%', '%USERNAME%');
         $replace = array($msg_content, $project->name, SITE_URL . "/project/" . $project->id, SITE_URL . "/user/profile/" . $project->owner, $project->owner, $value->name);
         $content = \str_replace($search, $replace, $template->text);
         try {
             $result = $sesClient->sendEmail(array('Source' => AWS_SES_SOURCE, 'Destination' => array('ToAddresses' => array($value->email)), 'Message' => array('Subject' => array('Data' => $subject, 'Charset' => AWS_SES_CHARSET), 'Body' => array('Text' => array('Data' => $msg_content, 'Charset' => AWS_SES_CHARSET), 'Html' => array('Data' => $content, 'Charset' => AWS_SES_CHARSET)))));
             Message::Info(Text::get('dashboard-investors-mail-sended', $value->name));
         } catch (SesException $exc) {
             Message::Error(Text::get('dashboard-investors-mail-fail', $value->name));
         }
     }
     return true;
     /* end */
     // - en la plantilla hay que cambiar %NAME% por %USERNAME% para que sender reemplace
     // -
     // - se crea un registro de tabla mail
     $sql = "INSERT INTO mail (id, email, html, template) VALUES ('', :email, :html, :template)";
     $values = array(':email' => 'any', ':html' => $content, ':template' => $template->id);
     $query = \Goteo\Core\Model::query($sql, $values);
     $mailId = \Goteo\Core\Model::insertId();
     // - se usa el metodo initializeSending para grabar el envío (parametro para autoactivar)
     // , también metemos el reply y repplyName (remitente) en la instancia de envío
     if (\Goteo\Library\Sender::initiateSending($mailId, $subject, $receivers, 1, $project->user->email, $remite)) {
         Message::Info(Text::get('dashboard-investors-mail-sended', 'la cola de envíos'));
         // cambiar este texto
     } else {
         Message::Error(Text::get('dashboard-investors-mail-fail', 'la cola de envíos'));
         // cambiar este texto
     }
     return true;
 }