Ejemplo n.º 1
0
 /**
  * mandril://APIKEY
  *
  * @param Envelope $envelope
  * @return bool
  * @throws MailApiException
  */
 public function send(Envelope $envelope)
 {
     $from = Util::decomposeEmail($envelope->getFrom());
     $fromName = $from['name'];
     $fromEmail = $from['email'];
     $bodyHtml = $envelope->getBody();
     $params = array();
     $params["key"] = $this->connection->getServer();
     $params["message"] = ['html' => $bodyHtml, 'subject' => $envelope->getSubject(), 'from_name' => $fromName, 'from_email' => $fromEmail, 'to' => [], 'headers' => ['Reply-To' => $envelope->getReplyTo()], "important" => false, "track_opens" => true, "track_clicks" => true, "auto_text" => true, "auto_html" => true];
     $params["async"] = true;
     $params["ip_pool"] = "Main Pool";
     $sendTo = array_unique(array_merge((array) $envelope->getTo(), (array) $envelope->getCC()));
     foreach ($sendTo as $email) {
         $params['message']['to'][] = ['email' => $email, 'type' => 'to'];
     }
     foreach ((array) $envelope->getBCC() as $email) {
         $params['message']['bcc_address'] = $email;
     }
     $json = json_encode($params);
     $request = new WebRequest('https://mandrillapp.com/api/1.0/messages/send.json');
     $result = $request->postPayload($json, 'application/json');
     if (!$result) {
         throw new MailApiException('Cannot connect to Mandrill Api');
     } else {
         $resultJson = json_decode($result, true);
         if ($resultJson[0]['status'] == 'error') {
             throw new MailApiException('Mandrill: ' . $resultJson[0]['message']);
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function delete($url, $params = null)
 {
     $req = new WebRequest($this->preparedUrl($url));
     $result = $req->delete($params);
     $this->_lastStatusCode = $req->getLastStatus();
     return $this->validateRequest($result);
 }
Ejemplo n.º 3
0
 /**
  * malgun://APIKEY@DOMAINNAME
  *
  * @param Envelope $envelope
  * @return bool
  * @throws MailApiException
  */
 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;
     }
     $domainName = $this->connection->getServer();
     $request = new WebRequest("https://api.mailgun.net/v3/{$domainName}/messages.mime");
     $request->setCredentials($this->connection->getUsername(), $this->connection->getPassword());
     $upload = [new UploadFile('message', $message, 'message.mime')];
     // Add "To;"
     foreach ((array) $envelope->getTo() as $toEmail) {
         $upload[] = new UploadFile('to', $toEmail);
     }
     $result = $request->postUploadFile($upload);
     $resultJson = json_decode($result, true);
     if (!isset($resultJson['id'])) {
         throw new MailApiException('Mailgun: ' . $resultJson['message']);
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Handle OAuth 2.0 Flow
  * @return BaseOAuth20
  */
 public function handle()
 {
     // Get Var Elements
     $accessToken = $this->getAccessToken();
     $state = $this->getVar("state");
     // Initiate OAuth Client with Specific server configuration
     $to = new $this->_className();
     // Try to Handle the Authentication Process
     if ($accessToken == "") {
         $code = $this->_context->get("code");
         // If not received the "Code" Parameter, initiate the autorization request
         if ($code == "") {
             $state = md5(uniqid(rand(), TRUE));
             //CSRF protection
             $this->setVar("state", $state);
             $params = array("client_id" => $this->_client_id, "redirect_uri" => $this->_redirect_uri, "state" => $state, "scope" => $this->_scope);
             if (count($this->_extraArgs) > 0) {
                 $params = array_merge($params, $this->_extraArgs);
             }
             $req = new WebRequest($to->authorizationURL());
             $req->redirect($params, $this->_window_top);
         }
         // Request the Access Token
         if ($this->_context->get("state") == $this->getVar("state")) {
             $params = array("client_id" => $this->_client_id, "redirect_uri" => $this->_redirect_uri, "client_secret" => $this->_client_secret, "code" => $code, "grant_type" => "authorization_code");
             $req = new WebRequest($to->accessTokenURL());
             $result = $req->post($params);
             $accessToken = $to->decodeAccessToken($result);
             $this->setVar("access_token", $accessToken);
             $to->setAccessToken($accessToken);
             $this->saveAccessToken();
             if ($this->_app_uri != "") {
                 $req = new WebRequest($this->_app_uri);
                 $response = $req->redirect();
             }
         }
     } else {
         $to->setAccessToken($this->getVar('access_token'));
     }
     return $to;
 }