summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2018-03-21 23:23:07 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2018-03-21 23:23:07 +0000
commit1b54ffd02e4dd50138a4482e0d9cb72dd17c4cf6 (patch)
treeb1dd25b31c371a34b193fd92e7c4f407e683e21d
parent14915f4914ff3f912b267aa034327101b3b170d5 (diff)
downloadPost-SMTP-1b54ffd02e4dd50138a4482e0d9cb72dd17c4cf6.zip
Fix sendgrid api call structure
-rw-r--r--Postman/Postman-Mail/PostmanSendGridMailEngine.php34
-rw-r--r--postman-smtp.php4
-rw-r--r--readme.txt2
3 files changed, 31 insertions, 9 deletions
diff --git a/Postman/Postman-Mail/PostmanSendGridMailEngine.php b/Postman/Postman-Mail/PostmanSendGridMailEngine.php
index 174f38a..b6ddb83 100644
--- a/Postman/Postman-Mail/PostmanSendGridMailEngine.php
+++ b/Postman/Postman-Mail/PostmanSendGridMailEngine.php
@@ -55,12 +55,24 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) {
// add the to recipients
$counter = 0;
$emails = array();
+ /**
+ * @todo: Find a better approch.
+ */
+ $duplicates = array();
foreach ( ( array ) $message->getToRecipients() as $recipient ) {
$recipient->log( $this->logger, 'To' );
+
+ $email = $recipient->getEmail();
if ( $counter == 0 ) {
+ $this->logger->debug( 'Adding to=' . $recipient->getEmail() );
$to = new SendGrid\Email( $recipient->getName(), $recipient->getEmail() );
+ $duplicates[] = $email;
} else {
- $emails[] = new SendGrid\Email( $recipient->getName(), $recipient->getEmail() );
+ if ( ! in_array( $email, $duplicates ) ) {
+ $duplicates[] = $email;
+ $this->logger->debug( 'Adding personalization to=' . $recipient->getEmail() );
+ $emails[] = new SendGrid\Email( $recipient->getName(), $recipient->getEmail() );
+ }
}
$counter++;
@@ -118,14 +130,20 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) {
// add the cc recipients
foreach ( ( array ) $message->getCcRecipients() as $recipient ) {
- $recipient->log( $this->logger, 'Cc' );
- $mail->personalization[0]->addCc( $recipient->getEmail(), $recipient->getName() );
+ if ( ! in_array( $recipient->getEmail(), $duplicates ) ) {
+ $recipient->log( $this->logger, 'Cc' );
+ $email = new SendGrid\Email( $recipient->getName(), $recipient->getEmail() );
+ $mail->personalization[0]->addCc( $email );
+ }
}
// add the bcc recipients
foreach ( ( array ) $message->getBccRecipients() as $recipient ) {
- $recipient->log( $this->logger, 'Bcc' );
- $mail->personalization[0]->addBcc( $recipient->getEmail(), $recipient->getName() );
+ if ( ! in_array( $recipient->getEmail(), $duplicates ) ) {
+ $recipient->log( $this->logger, 'Bcc' );
+ $email = new SendGrid\Email( $recipient->getName(), $recipient->getEmail() );
+ $mail->personalization[0]->addBcc( $email );
+ }
}
// add the messageId
@@ -163,7 +181,7 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) {
$response = $sendgrid->client->mail()->send()->post( $mail );
if ( $this->logger->isInfo() ) {
- $this->logger->info( );
+ $this->logger->info( sprintf( 'Message %d accepted for delivery', PostmanState::getInstance()->getSuccessfulDeliveries() + 1 ) );
}
$response_body = json_decode( $response->body() );
@@ -172,6 +190,9 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) {
$this->transcript = $response_body->errors[0]->message;
$this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
$this->transcript .= print_r( $mail, true );
+
+ $this->logger->debug( 'Transcript=' . $this->transcript );
+
throw new Exception( $response_body->errors[0]->message );
}
$this->transcript = print_r( $response->body(), true );
@@ -181,6 +202,7 @@ if ( ! class_exists( 'PostmanSendGridMailEngine' ) ) {
$this->transcript = $e->getMessage();
$this->transcript .= PostmanModuleTransport::RAW_MESSAGE_FOLLOWS;
$this->transcript .= print_r( $mail, true );
+ $this->logger->debug( 'Transcript=' . $this->transcript );
throw $e;
}
}
diff --git a/postman-smtp.php b/postman-smtp.php
index 7b557ef..0f9cc3d 100644
--- a/postman-smtp.php
+++ b/postman-smtp.php
@@ -4,7 +4,7 @@
* Plugin Name: Post SMTP
* Plugin URI: https://wordpress.org/plugins/post-smtp/
* Description: Email not reliable? Post SMTP is the first and only WordPress SMTP plugin to implement OAuth 2.0 for Gmail, Hotmail and Yahoo Mail. Setup is a breeze with the Configuration Wizard and integrated Port Tester. Enjoy worry-free delivery even if your password changes!
- * Version: 1.8.2
+ * Version: 1.8.3
* Author: Jason Hendriks, Yehuda Hassine
* Text Domain: post-smtp
* Author URI: https://postmansmtp.com
@@ -71,5 +71,5 @@ function post_start( $startingMemory ) {
*/
function post_setupPostman() {
require_once 'Postman/Postman.php';
- $kevinCostner = new Postman( __FILE__, '1.8.2' );
+ $kevinCostner = new Postman( __FILE__, '1.8.3' );
}
diff --git a/readme.txt b/readme.txt
index 7297e68..2fd0633 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=yehuda@m
Tags: postman smtp, postman, smtp, email, mail, mailer, email log, oauth2, gmail, google apps, hotmail, yahoo, mandrill api, sendgrid api, elastic email, office365, mailgun
Requires at least: 3.9
Tested up to: 4.9.4
-Stable tag: 1.8.2
+Stable tag: 1.8.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html