summaryrefslogtreecommitdiff
path: root/Postman/Postman-Mail
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-12-23 23:23:04 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-12-23 23:23:04 +0000
commit707146a8ea285d5f51e112dabad57785b38f3b3a (patch)
tree1ce0952fd8a89cdc8308f32d09763169cb017dc4 /Postman/Postman-Mail
parent6eabf1113cb0837b3ee83c058d9d68fca72e1b71 (diff)
downloadPost-SMTP-707146a8ea285d5f51e112dabad57785b38f3b3a.zip
= 1.8 - 2017-12-24
* New: Mailgun API integration * New: New filter controls * New: WPML conflict fix * Fix: Minor old bugs
Diffstat (limited to 'Postman/Postman-Mail')
-rw-r--r--Postman/Postman-Mail/PostmanMailgunMailEngine.php38
-rw-r--r--Postman/Postman-Mail/PostmanMailgunTransport.php2
-rw-r--r--Postman/Postman-Mail/PostmanTransportRegistry.php2
3 files changed, 38 insertions, 4 deletions
diff --git a/Postman/Postman-Mail/PostmanMailgunMailEngine.php b/Postman/Postman-Mail/PostmanMailgunMailEngine.php
index 360201c..58def41 100644
--- a/Postman/Postman-Mail/PostmanMailgunMailEngine.php
+++ b/Postman/Postman-Mail/PostmanMailgunMailEngine.php
@@ -90,7 +90,7 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) {
$recipient->log( $this->logger, 'To' );
$recipients[] = $recipient->getEmail();
}
- $this->mailgunMessage['to'] = implode( ',', $recipients );
+ $this->mailgunMessage['to'] = $recipients;
// add the cc recipients
$recipients = array();
@@ -164,7 +164,7 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) {
$mg = Mailgun::create( $this->apiKey );
// Make the call to the client.
- $result = $mg->messages()->send( $this->domainName, array_filter( $this->mailgunMessage ) );
+ $result = $this->processSend( $mg );
if ( $this->logger->isInfo() ) {
$this->logger->info( sprintf( 'Message %d accepted for delivery', PostmanState::getInstance()->getSuccessfulDeliveries() + 1 ) );
@@ -181,6 +181,40 @@ if ( ! class_exists( 'PostmanMailgunMailEngine' ) ) {
}
}
+
+ private function processSend( $mg ) {
+
+ if ( count( $this->mailgunMessage['to'] ) == 1 ) {
+
+ return $mg->messages()->send( $this->domainName, array_filter( $this->mailgunMessage ) );
+ } else {
+ $chunks = array_chunk( $this->mailgunMessage['to'], 1000, true );
+
+ $result = array();
+ foreach ( $chunks as $key => $emails ) {
+ $this->mailgunMessage['to'] = $emails;
+ $recipient_variables = $this->getRecipientVariables( $emails );
+ $this->mailgunMessage['recipient-variables'] = $recipient_variables;
+
+ $result[] = $mg->messages()->send( $this->domainName, array_filter( $this->mailgunMessage ) );
+
+ // Don't have a reason just wait a bit before sending the next chunk
+ sleep(2);
+ }
+
+ return $result;
+ }
+ }
+
+ private function getRecipientVariables( $emails ) {
+ $recipient_variables = array();
+ foreach ( $emails as $key => $email ) {
+ $recipient_variables[$email] = array( 'id' => $key );
+ }
+
+ return json_encode( $recipient_variables );
+ }
+
private function addHeader( $name, $value, $deprecated = '' ) {
if ( $value && ! empty( $value ) ) {
$this->mailgunMessage['h:' . $name] = $value;
diff --git a/Postman/Postman-Mail/PostmanMailgunTransport.php b/Postman/Postman-Mail/PostmanMailgunTransport.php
index c3565ea..9a5e9d2 100644
--- a/Postman/Postman-Mail/PostmanMailgunTransport.php
+++ b/Postman/Postman-Mail/PostmanMailgunTransport.php
@@ -154,7 +154,7 @@ class PostmanMailgunTransport extends PostmanAbstractModuleTransport implements
$overrideItem ['auth_items'] = array(
array(
'selected' => true,
- 'name' => __( 'API Kkey', Postman::TEXT_DOMAIN ),
+ 'name' => __( 'API Key', Postman::TEXT_DOMAIN ),
'value' => 'api_key',
),
);
diff --git a/Postman/Postman-Mail/PostmanTransportRegistry.php b/Postman/Postman-Mail/PostmanTransportRegistry.php
index ceaef7c..77654eb 100644
--- a/Postman/Postman-Mail/PostmanTransportRegistry.php
+++ b/Postman/Postman-Mail/PostmanTransportRegistry.php
@@ -234,7 +234,7 @@ class PostmanTransportRegistry {
return __( 'Postman is configured.', Postman::TEXT_DOMAIN );
}
} else {
- return '<div class="updated error otgs-is-dismissible settings-error notice is-dismissible" style="20px;">' . __( 'Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN ) . '</div>';
+ return __( 'Postman is <em>not</em> configured and is mimicking out-of-the-box WordPress email delivery.', Postman::TEXT_DOMAIN );
}
}
}