- Adds "reply to" option to all mailers
- Replaces WPMail with Swift using local transport (PHP mail) - Fixes AmazonSES region naming convention - Updates tests
This commit is contained in:
@@ -27,63 +27,65 @@ class Mailer {
|
||||
|
||||
function buildMailer() {
|
||||
switch($this->mailer['method']) {
|
||||
case 'AmazonSES':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['region'],
|
||||
$this->mailer['access_key'],
|
||||
$this->mailer['secret_key'],
|
||||
$this->sender['from_name_email']
|
||||
);
|
||||
break;
|
||||
case 'ElasticEmail':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['api_key'],
|
||||
$this->sender['from_email'],
|
||||
$this->sender['from_name']
|
||||
);
|
||||
break;
|
||||
case 'MailGun':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['domain'],
|
||||
$this->mailer['api_key'],
|
||||
$this->sender['from_name_email']
|
||||
);
|
||||
break;
|
||||
case 'MailPoet':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['mailpoet_api_key'],
|
||||
$this->sender['from_email'],
|
||||
$this->sender['from_name']
|
||||
);
|
||||
break;
|
||||
case 'SendGrid':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['api_key'],
|
||||
$this->sender['from_email'],
|
||||
$this->sender['from_name']
|
||||
);
|
||||
break;
|
||||
case 'WPMail':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->sender['from_email'],
|
||||
$this->sender['from_name']
|
||||
);
|
||||
break;
|
||||
case 'SMTP':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['host'],
|
||||
$this->mailer['port'],
|
||||
$this->mailer['authentication'],
|
||||
$this->mailer['login'],
|
||||
$this->mailer['password'],
|
||||
$this->mailer['encryption'],
|
||||
$this->sender['from_email'],
|
||||
$this->sender['from_name']
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception(__('Mailing method does not exist.'));
|
||||
break;
|
||||
case 'AmazonSES':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['region'],
|
||||
$this->mailer['access_key'],
|
||||
$this->mailer['secret_key'],
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
case 'ElasticEmail':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['api_key'],
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
case 'MailGun':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['domain'],
|
||||
$this->mailer['api_key'],
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
case 'MailPoet':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['mailpoet_api_key'],
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
case 'SendGrid':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['api_key'],
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
case 'PHPMail':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
case 'SMTP':
|
||||
$mailer_instance = new $this->mailer['class'](
|
||||
$this->mailer['host'],
|
||||
$this->mailer['port'],
|
||||
$this->mailer['authentication'],
|
||||
$this->mailer['login'],
|
||||
$this->mailer['password'],
|
||||
$this->mailer['encryption'],
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception(__('Mailing method does not exist.'));
|
||||
break;
|
||||
}
|
||||
return $mailer_instance;
|
||||
}
|
||||
@@ -119,6 +121,9 @@ class Mailer {
|
||||
);
|
||||
}
|
||||
}
|
||||
if(!$reply_to['address']) {
|
||||
$reply_to['reply_to_email'] = $this->sender['from_email'];
|
||||
}
|
||||
return array(
|
||||
'reply_to_name' => $reply_to['name'],
|
||||
'reply_to_email' => $reply_to['address'],
|
||||
|
@@ -13,21 +13,23 @@ class AmazonSES {
|
||||
public $aws_termination_string;
|
||||
public $hash_algorithm;
|
||||
public $url;
|
||||
public $from;
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
public $date;
|
||||
public $date_without_time;
|
||||
|
||||
function __construct($region, $access_key, $secret_key, $from) {
|
||||
function __construct($region, $access_key, $secret_key, $sender, $reply_to) {
|
||||
$this->aws_access_key = $access_key;
|
||||
$this->aws_secret_key = $secret_key;
|
||||
$this->aws_region = $region;
|
||||
$this->aws_endpoint = sprintf('email.%s.amazonaws.com', $region);
|
||||
$this->aws_endpoint = sprintf('email.%s.amazonaws.com', $this->aws_region);
|
||||
$this->aws_signing_algorithm = 'AWS4-HMAC-SHA256';
|
||||
$this->aws_service = 'ses';
|
||||
$this->aws_termination_string = 'aws4_request';
|
||||
$this->hash_algorithm = 'sha256';
|
||||
$this->url = 'https://' . $this->aws_endpoint;
|
||||
$this->from = $from;
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
$this->date = gmdate('Ymd\THis\Z');
|
||||
$this->date_without_time = gmdate('Ymd');
|
||||
}
|
||||
@@ -47,10 +49,11 @@ class AmazonSES {
|
||||
$body = array(
|
||||
'Action' => 'SendEmail',
|
||||
'Version' => '2010-12-01',
|
||||
'Source' => $this->from,
|
||||
'Destination.ToAddresses.member.1' => $subscriber,
|
||||
'Source' => $this->sender['from_name_email'],
|
||||
'ReplyToAddresses.member.1' => $this->reply_to['reply_to_name_email'],
|
||||
'Message.Subject.Data' => $newsletter['subject'],
|
||||
'ReturnPath' => $this->from
|
||||
'ReturnPath' => $this->sender['from_name_email'],
|
||||
);
|
||||
if(!empty($newsletter['body']['html'])) {
|
||||
$body['Message.Body.Html.Data'] = $newsletter['body']['html'];
|
||||
|
@@ -6,13 +6,13 @@ if(!defined('ABSPATH')) exit;
|
||||
class ElasticEmail {
|
||||
public $url = 'https://api.elasticemail.com/mailer/send';
|
||||
public $api_key;
|
||||
public $from_email;
|
||||
public $from_name;
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($api_key, $sender, $reply_to) {
|
||||
$this->api_key = $api_key;
|
||||
$this->from_email = $from_email;
|
||||
$this->from_name = $from_name;
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@@ -28,9 +28,11 @@ class ElasticEmail {
|
||||
function getBody($newsletter, $subscriber) {
|
||||
$body = array(
|
||||
'api_key' => $this->api_key,
|
||||
'from' => $this->from_email,
|
||||
'from_name' => $this->from_name,
|
||||
'to' => $subscriber,
|
||||
'from' => $this->sender['from_email'],
|
||||
'from_name' => $this->sender['from_name'],
|
||||
'reply_to' => $this->reply_to['reply_to_email'],
|
||||
'reply_to_name' => $this->reply_to['reply_to_name'],
|
||||
'subject' => $newsletter['subject']
|
||||
);
|
||||
if(!empty($newsletter['body']['html'])) {
|
||||
|
@@ -6,12 +6,14 @@ if(!defined('ABSPATH')) exit;
|
||||
class MailGun {
|
||||
public $url;
|
||||
public $api_key;
|
||||
public $from;
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
|
||||
function __construct($domain, $api_key, $from) {
|
||||
function __construct($domain, $api_key, $sender, $reply_to) {
|
||||
$this->url = sprintf('https://api.mailgun.net/v3/%s/messages', $domain);
|
||||
$this->api_key = $api_key;
|
||||
$this->from = $from;
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@@ -27,8 +29,9 @@ class MailGun {
|
||||
|
||||
function getBody($newsletter, $subscriber) {
|
||||
$body = array(
|
||||
'from' => $this->from,
|
||||
'to' => $subscriber,
|
||||
'from' => $this->sender['from_name_email'],
|
||||
'h:Reply-To' => $this->reply_to['reply_to_name_email'],
|
||||
'subject' => $newsletter['subject']
|
||||
);
|
||||
if(!empty($newsletter['body']['html'])) {
|
||||
|
@@ -6,13 +6,13 @@ if(!defined('ABSPATH')) exit;
|
||||
class MailPoet {
|
||||
public $url = 'https://bridge.mailpoet.com/api/messages';
|
||||
public $api_key;
|
||||
public $from_email;
|
||||
public $from_name;
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($api_key, $sender, $reply_to) {
|
||||
$this->api_key = $api_key;
|
||||
$this->from_email = $from_email;
|
||||
$this->from_name = $from_name;
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@@ -46,8 +46,12 @@ class MailPoet {
|
||||
'name' => $subscriber['name']
|
||||
)),
|
||||
'from' => (array(
|
||||
'address' => $this->from_email,
|
||||
'name' => $this->from_name
|
||||
'address' => $this->sender['from_email'],
|
||||
'name' => $this->sender['from_name']
|
||||
)),
|
||||
'reply_to' => (array(
|
||||
'address' => $this->reply_to['reply_to_email'],
|
||||
'name' => $this->reply_to['reply_to_name']
|
||||
)),
|
||||
'subject' => $newsletter['subject']
|
||||
);
|
||||
|
64
lib/Mailer/Methods/PHPMail.php
Normal file
64
lib/Mailer/Methods/PHPMail.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer\Methods;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class PHPMail {
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
public $mailer;
|
||||
|
||||
function __construct($sender, $reply_to) {
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
$this->mailer = $this->buildMailer();
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
try {
|
||||
$message = $this->createMessage($newsletter, $subscriber);
|
||||
$result = $this->mailer->send($message);
|
||||
} catch(\Exception $e) {
|
||||
$result = false;
|
||||
}
|
||||
return ($result === 1);
|
||||
}
|
||||
|
||||
function buildMailer() {
|
||||
$transport = \Swift_SmtpTransport::newInstance();
|
||||
$transport->setTimeout(10);
|
||||
return \Swift_Mailer::newInstance($transport);
|
||||
}
|
||||
|
||||
function createMessage($newsletter, $subscriber) {
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setTo($this->processSubscriber($subscriber))
|
||||
->setFrom(array(
|
||||
$this->sender['from_email'] => $this->sender['from_name']
|
||||
))
|
||||
->setReplyTo(array(
|
||||
$this->reply_to['reply_to_email'] => $this->reply_to['reply_to_name']
|
||||
))
|
||||
->setSubject($newsletter['subject']);
|
||||
if(!empty($newsletter['body']['html'])) {
|
||||
$message = $message->setBody($newsletter['body']['html'], 'text/html');
|
||||
}
|
||||
if(!empty($newsletter['body']['text'])) {
|
||||
$message = $message->addPart($newsletter['body']['text'], 'text/plain');
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
function processSubscriber($subscriber) {
|
||||
preg_match('!(?P<name>.*?)\s<(?P<email>.*?)>!', $subscriber, $subscriber_data);
|
||||
if(!isset($subscriber_data['email'])) {
|
||||
$subscriber_data = array(
|
||||
'email' => $subscriber,
|
||||
);
|
||||
}
|
||||
return array(
|
||||
$subscriber_data['email'] =>
|
||||
(isset($subscriber_data['name'])) ? $subscriber_data['name'] : ''
|
||||
);
|
||||
}
|
||||
}
|
@@ -10,21 +10,21 @@ class SMTP {
|
||||
public $login;
|
||||
public $password;
|
||||
public $encryption;
|
||||
public $from_name;
|
||||
public $from_email;
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
public $mailer;
|
||||
|
||||
function __construct(
|
||||
$host, $port, $authentication, $login = null, $password = null, $encryption,
|
||||
$from_email, $from_name) {
|
||||
$sender, $reply_to) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->authentication = $authentication;
|
||||
$this->login = $login;
|
||||
$this->password = $password;
|
||||
$this->encryption = $encryption;
|
||||
$this->from_name = $from_name;
|
||||
$this->from_email = $from_email;
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
$this->mailer = $this->buildMailer();
|
||||
}
|
||||
|
||||
@@ -50,11 +50,15 @@ class SMTP {
|
||||
return \Swift_Mailer::newInstance($transport);
|
||||
}
|
||||
|
||||
|
||||
function createMessage($newsletter, $subscriber) {
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setFrom(array($this->from_email => $this->from_name))
|
||||
->setTo($this->processSubscriber($subscriber))
|
||||
->setFrom(array(
|
||||
$this->sender['from_email'] => $this->sender['from_name']
|
||||
))
|
||||
->setReplyTo(array(
|
||||
$this->reply_to['reply_to_email'] => $this->reply_to['reply_to_name']
|
||||
))
|
||||
->setSubject($newsletter['subject']);
|
||||
if(!empty($newsletter['body']['html'])) {
|
||||
$message = $message->setBody($newsletter['body']['html'], 'text/html');
|
||||
|
@@ -6,13 +6,13 @@ if(!defined('ABSPATH')) exit;
|
||||
class SendGrid {
|
||||
public $url = 'https://api.sendgrid.com/api/mail.send.json';
|
||||
public $api_key;
|
||||
public $from_email;
|
||||
public $from_name;
|
||||
public $sender;
|
||||
public $reply_to;
|
||||
|
||||
function __construct($api_key, $from_email, $from_name) {
|
||||
function __construct($api_key, $sender, $reply_to) {
|
||||
$this->api_key = $api_key;
|
||||
$this->from_email = $from_email;
|
||||
$this->from_name = $from_name;
|
||||
$this->sender = $sender;
|
||||
$this->reply_to = $reply_to;
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
@@ -31,8 +31,9 @@ class SendGrid {
|
||||
function getBody($newsletter, $subscriber) {
|
||||
$body = array(
|
||||
'to' => $subscriber,
|
||||
'from' => $this->from_email,
|
||||
'from_name' => $this->from_name,
|
||||
'from' => $this->sender['from_email'],
|
||||
'fromname' => $this->sender['from_name'],
|
||||
'replyto' => $this->reply_to['reply_to_email'],
|
||||
'subject' => $newsletter['subject']
|
||||
);
|
||||
if(!empty($newsletter['body']['html'])) {
|
||||
|
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer\Methods;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class WPMail {
|
||||
public $from_email;
|
||||
public $from_name;
|
||||
public $filters = array(
|
||||
'wp_mail_from' => 'setFromEmail',
|
||||
'wp_mail_from_name' => 'setFromName',
|
||||
'wp_mail_content_type' => 'setContentType'
|
||||
);
|
||||
|
||||
function __construct($from_email, $from_name) {
|
||||
$this->from_email = $from_email;
|
||||
$this->from_name = $from_name;
|
||||
}
|
||||
|
||||
function addFilters() {
|
||||
foreach($this->filters as $filter => $method) {
|
||||
add_filter($filter, array(
|
||||
$this,
|
||||
$method
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function removeFilters() {
|
||||
foreach($this->filters as $filter => $method) {
|
||||
remove_filter($filter, array(
|
||||
$this,
|
||||
$method
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function setFromEmail() {
|
||||
return $this->from_email;
|
||||
}
|
||||
|
||||
function setFromName() {
|
||||
return $this->from_name;
|
||||
}
|
||||
|
||||
function setContentType() {
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
function send($newsletter, $subscriber) {
|
||||
$this->addFilters();
|
||||
$result = wp_mail(
|
||||
$subscriber, $newsletter['subject'],
|
||||
(!empty($newsletter['body']['html'])) ?
|
||||
$newsletter['body']['html'] :
|
||||
$newsletter['body']['text']
|
||||
);
|
||||
$this->removeFilters();
|
||||
return ($result === true);
|
||||
}
|
||||
}
|
@@ -13,9 +13,9 @@ class Hosts {
|
||||
'secret_key'
|
||||
),
|
||||
'regions' => array(
|
||||
'US East (N. Virginia)' => 'us-east-1.amazonaws.com',
|
||||
'US West (Oregon)' => 'us-west-2.amazonaws.com',
|
||||
'EU (Ireland)' => 'eu-west-1.amazonaws.com'
|
||||
'US East (N. Virginia)' => 'us-east-1',
|
||||
'US West (Oregon)' => 'us-west-2',
|
||||
'EU (Ireland)' => 'eu-west-1'
|
||||
)
|
||||
),
|
||||
'ElasticEmail' => array(
|
||||
|
@@ -6,16 +6,27 @@ class AmazonSESCest {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'method' => 'AmazonSES',
|
||||
'access_key' => 'AKIAJM6Y5HMGXBLDNSRA',
|
||||
'secret_key' => 'P3EbTbVx7U0LXKQ9nTm2eIrP+9aPiLyvaRDsFxXh',
|
||||
'region' => 'us-east-1',
|
||||
'access_key' => 'AKIAJDCYK7DHCRVF7LXA',
|
||||
'secret_key' => 'xVv9cKLf38d630YECGZMg7tb1kkN6GTG58WNBP9q',
|
||||
'region' => 'us-west-2',
|
||||
);
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->from = 'Sender <vlad@mailpoet.com>';
|
||||
$this->mailer = new AmazonSES(
|
||||
$this->settings['region'],
|
||||
$this->settings['access_key'],
|
||||
$this->settings['secret_key'],
|
||||
$this->from);
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
'subject' => 'testing AmazonSES',
|
||||
@@ -33,8 +44,8 @@ class AmazonSESCest {
|
||||
);
|
||||
expect($this->mailer->url)
|
||||
->equals(
|
||||
sprintf('https://email.%s.amazonaws.com', $this->settings['region'])
|
||||
);
|
||||
sprintf('https://email.%s.amazonaws.com', $this->settings['region'])
|
||||
);
|
||||
expect(preg_match('!^\d{8}T\d{6}Z$!', $this->mailer->date))->equals(1);
|
||||
expect(preg_match('!^\d{8}$!', $this->mailer->date_without_time))->equals(1);
|
||||
}
|
||||
@@ -43,7 +54,9 @@ class AmazonSESCest {
|
||||
$body = $this->mailer->getBody($this->newsletter, $this->subscriber);
|
||||
expect($body['Action'])->equals('SendEmail');
|
||||
expect($body['Version'])->equals('2010-12-01');
|
||||
expect($body['Source'])->equals($this->from);
|
||||
expect($body['Source'])->equals($this->sender['from_name_email']);
|
||||
expect($body['ReplyToAddresses.member.1'])
|
||||
->equals($this->reply_to['reply_to_name_email']);
|
||||
expect($body['Destination.ToAddresses.member.1'])
|
||||
->contains($this->subscriber);
|
||||
expect($body['Message.Subject.Data'])
|
||||
@@ -52,7 +65,7 @@ class AmazonSESCest {
|
||||
->equals($this->newsletter['body']['html']);
|
||||
expect($body['Message.Body.Text.Data'])
|
||||
->equals($this->newsletter['body']['text']);
|
||||
expect($body['ReturnPath'])->equals($this->from);
|
||||
expect($body['ReturnPath'])->equals($this->sender['from_name_email']);
|
||||
}
|
||||
|
||||
function itCanCreateRequest() {
|
||||
|
@@ -8,12 +8,20 @@ class ElasticEmailCest {
|
||||
'method' => 'ElasticEmail',
|
||||
'api_key' => '997f1f7f-41de-4d7f-a8cb-86c8481370fa'
|
||||
);
|
||||
$this->from_email = 'staff@mailpoet.com';
|
||||
$this->from_name = 'Sender';
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->mailer = new ElasticEmail(
|
||||
$this->settings['api_key'],
|
||||
$this->from_email,
|
||||
$this->from_name
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
@@ -28,8 +36,10 @@ class ElasticEmailCest {
|
||||
function itCanGenerateBody() {
|
||||
$body = $this->mailer->getBody($this->newsletter, $this->subscriber);
|
||||
expect($body['api_key'])->equals($this->settings['api_key']);
|
||||
expect($body['from'])->equals($this->from_email);
|
||||
expect($body['from_name'])->equals($this->from_name);
|
||||
expect($body['from'])->equals($this->sender['from_email']);
|
||||
expect($body['from_name'])->equals($this->sender['from_name']);
|
||||
expect($body['reply_to'])->equals($this->reply_to['reply_to_email']);
|
||||
expect($body['reply_to_name'])->equals($this->reply_to['reply_to_name']);
|
||||
expect($body['to'])->contains($this->subscriber);
|
||||
expect($body['subject'])->equals($this->newsletter['subject']);
|
||||
expect($body['body_html'])->equals($this->newsletter['body']['html']);
|
||||
|
@@ -9,11 +9,21 @@ class MailGunCest {
|
||||
'api_key' => 'key-6cf5g5qjzenk-7nodj44gdt8phe6vam2',
|
||||
'domain' => 'mrcasual.com'
|
||||
);
|
||||
$this->from = 'Sender <staff@mailpoet.com>';
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->mailer = new MailGun(
|
||||
$this->settings['domain'],
|
||||
$this->settings['api_key'],
|
||||
$this->from
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
@@ -27,7 +37,8 @@ class MailGunCest {
|
||||
|
||||
function itCanGenerateBody() {
|
||||
$body = $this->mailer->getBody($this->newsletter, $this->subscriber);
|
||||
expect($body['from'])->equals($this->from);
|
||||
expect($body['from'])->equals($this->sender['from_name_email']);
|
||||
expect($body['h:Reply-To'])->equals($this->reply_to['reply_to_name_email']);
|
||||
expect($body['to'])->equals($this->subscriber);
|
||||
expect($body['subject'])->equals($this->newsletter['subject']);
|
||||
expect($body['html'])->equals($this->newsletter['body']['html']);
|
||||
|
@@ -8,12 +8,20 @@ class MailPoetCest {
|
||||
'method' => 'MailPoet',
|
||||
'api_key' => 'dhNSqj1XHkVltIliyQDvMiKzQShOA5rs0m_DdRUVZHU'
|
||||
);
|
||||
$this->from_email = 'staff@mailpoet.com';
|
||||
$this->from_name = 'Sender';
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->mailer = new MailPoet(
|
||||
$this->settings['api_key'],
|
||||
$this->from_email,
|
||||
$this->from_name
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
@@ -30,7 +38,10 @@ class MailPoetCest {
|
||||
$body = $this->mailer->getBody($this->newsletter, $subscriber);
|
||||
expect($body['to']['address'])->equals($subscriber['email']);
|
||||
expect($body['to']['name'])->equals($subscriber['name']);
|
||||
expect($body['from']['address'])->equals($this->from_email);
|
||||
expect($body['from']['address'])->equals($this->sender['from_email']);
|
||||
expect($body['from']['name'])->equals($this->sender['from_name']);
|
||||
expect($body['reply_to']['address'])->equals($this->reply_to['reply_to_email']);
|
||||
expect($body['reply_to']['name'])->equals($this->reply_to['reply_to_name']);
|
||||
expect($body['subject'])->equals($this->newsletter['subject']);
|
||||
expect($body['html'])->equals($this->newsletter['body']['html']);
|
||||
expect($body['text'])->equals($this->newsletter['body']['text']);
|
||||
|
69
tests/unit/Mailer/Methods/PHPMailCest.php
Normal file
69
tests/unit/Mailer/Methods/PHPMailCest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Mailer\Methods\PHPMail;
|
||||
|
||||
class WPMailCest {
|
||||
function _before() {
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->mailer = new PHPMail(
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
'subject' => 'testing local method (PHP mail)',
|
||||
'body' => array(
|
||||
'html' => 'HTML body',
|
||||
'text' => 'TEXT body'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function itCanBuildMailer() {
|
||||
$mailer = $this->mailer->buildMailer();
|
||||
expect($mailer->getTransport()->getHost())
|
||||
->equals('localhost');
|
||||
}
|
||||
|
||||
function itCanCreateMessage() {
|
||||
$message = $this->mailer->createMessage($this->newsletter, $this->subscriber);
|
||||
expect($message->getTo())
|
||||
->equals(array('mailpoet-phoenix-test@mailinator.com' => 'Recipient'));
|
||||
expect($message->getFrom())
|
||||
->equals(array($this->sender['from_email'] => $this->sender['from_name']));
|
||||
expect($message->getReplyTo())
|
||||
->equals(array($this->reply_to['reply_to_email'] => $this->reply_to['reply_to_name']));
|
||||
expect($message->getSubject())
|
||||
->equals($this->newsletter['subject']);
|
||||
expect($message->getBody())
|
||||
->equals($this->newsletter['body']['html']);
|
||||
expect($message->getChildren()[0]->getContentType())
|
||||
->equals('text/plain');
|
||||
}
|
||||
|
||||
function itCanProcessSubscriber() {
|
||||
expect($this->mailer->processSubscriber('test@test.com'))
|
||||
->equals(array('test@test.com' => ''));
|
||||
expect($this->mailer->processSubscriber('First <test@test.com>'))
|
||||
->equals(array('test@test.com' => 'First'));
|
||||
expect($this->mailer->processSubscriber('First Last <test@test.com>'))
|
||||
->equals(array('test@test.com' => 'First Last'));
|
||||
}
|
||||
|
||||
function itCanSend() {
|
||||
$result = $this->mailer->send(
|
||||
$this->newsletter,
|
||||
$this->subscriber
|
||||
);
|
||||
expect($result)->true();
|
||||
}
|
||||
}
|
@@ -13,8 +13,16 @@ class SMTPCest {
|
||||
'authentication' => '1',
|
||||
'encryption' => 'tls'
|
||||
);
|
||||
$this->from_email = 'staff@mailpoet.com';
|
||||
$this->from_name = 'Sender';
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->mailer = new SMTP(
|
||||
$this->settings['host'],
|
||||
$this->settings['port'],
|
||||
@@ -22,8 +30,8 @@ class SMTPCest {
|
||||
$this->settings['login'],
|
||||
$this->settings['password'],
|
||||
$this->settings['encryption'],
|
||||
$this->from_email,
|
||||
$this->from_name
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
@@ -54,7 +62,9 @@ class SMTPCest {
|
||||
expect($message->getTo())
|
||||
->equals(array('mailpoet-phoenix-test@mailinator.com' => 'Recipient'));
|
||||
expect($message->getFrom())
|
||||
->equals(array($this->from_email => $this->from_name));
|
||||
->equals(array($this->sender['from_email'] => $this->sender['from_name']));
|
||||
expect($message->getReplyTo())
|
||||
->equals(array($this->reply_to['reply_to_email'] => $this->reply_to['reply_to_name']));
|
||||
expect($message->getSubject())
|
||||
->equals($this->newsletter['subject']);
|
||||
expect($message->getBody())
|
||||
|
@@ -8,12 +8,20 @@ class SendGridCest {
|
||||
'method' => 'SendGrid',
|
||||
'api_key' => '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'
|
||||
);
|
||||
$this->from_email = 'staff@mailpoet.com';
|
||||
$this->from_name = 'Sender';
|
||||
$this->sender = array(
|
||||
'from_name' => 'Sender',
|
||||
'from_email' => 'staff@mailpoet.com',
|
||||
'from_name_email' => 'Sender <staff@mailpoet.com>'
|
||||
);
|
||||
$this->reply_to = array(
|
||||
'reply_to_name' => 'Reply To',
|
||||
'reply_to_email' => 'reply-to@mailpoet.com',
|
||||
'reply_to_name_email' => 'Reply To <reply-to@mailpoet.com>'
|
||||
);
|
||||
$this->mailer = new SendGrid(
|
||||
$this->settings['api_key'],
|
||||
$this->from_email,
|
||||
$this->from_name
|
||||
$this->sender,
|
||||
$this->reply_to
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
@@ -28,8 +36,9 @@ class SendGridCest {
|
||||
function itCanGenerateBody() {
|
||||
$body = $this->mailer->getBody($this->newsletter, $this->subscriber);
|
||||
expect($body['to'])->contains($this->subscriber);
|
||||
expect($body['from'])->equals($this->from_email);
|
||||
expect($body['from_name'])->equals($this->from_name);
|
||||
expect($body['from'])->equals($this->sender['from_email']);
|
||||
expect($body['fromname'])->equals($this->sender['from_name']);
|
||||
expect($body['replyto'])->equals($this->reply_to['reply_to_email']);
|
||||
expect($body['subject'])->equals($this->newsletter['subject']);
|
||||
expect($body['html'])->equals($this->newsletter['body']['html']);
|
||||
expect($body['text'])->equals($this->newsletter['body']['text']);
|
||||
|
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Mailer\Methods\WPMail;
|
||||
|
||||
class WPMailCest {
|
||||
function _before() {
|
||||
$this->settings = array(
|
||||
'method' => 'WPMail'
|
||||
);
|
||||
$this->from_email = 'staff@mailpoet.com';
|
||||
$this->from_name = 'Sender';
|
||||
$this->mailer = new WPMail(
|
||||
$this->from_email,
|
||||
$this->from_name
|
||||
);
|
||||
$this->subscriber = 'Recipient <mailpoet-phoenix-test@mailinator.com>';
|
||||
$this->newsletter = array(
|
||||
'subject' => 'testing SMTP',
|
||||
'body' => array(
|
||||
'html' => 'HTML body',
|
||||
'text' => 'TEXT body'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function itCanAddFilters() {
|
||||
$this->mailer->addFilters();
|
||||
expect(has_filter('wp_mail_from_name', array(
|
||||
$this->mailer,
|
||||
'setFromName'
|
||||
)))->notEmpty();
|
||||
expect(has_filter('wp_mail_from', array(
|
||||
$this->mailer,
|
||||
'setFromEmail'
|
||||
)))->notEmpty();
|
||||
expect(has_filter('wp_mail_content_type', array(
|
||||
$this->mailer,
|
||||
'setContentType'
|
||||
)))->notEmpty();
|
||||
}
|
||||
|
||||
function itCanRemoveFilters() {
|
||||
$this->mailer->addFilters();
|
||||
$this->mailer->removeFilters();
|
||||
expect(has_filter('wp_mail_from_name'))->false();
|
||||
expect(has_filter('wp_mail_from'))->false();
|
||||
expect(has_filter('wp_mail_content_type'))->false();
|
||||
}
|
||||
|
||||
function itCanSetFromName() {
|
||||
expect($this->mailer->setFromName())->equals($this->from_name);
|
||||
}
|
||||
|
||||
function itCanSetFromEmail() {
|
||||
expect($this->mailer->setFromEmail())->equals($this->from_email);
|
||||
}
|
||||
|
||||
function itCanSetContentType() {
|
||||
expect($this->mailer->setContentType())->equals('text/html');
|
||||
}
|
||||
|
||||
function itCanSend() {
|
||||
$_SERVER['SERVER_NAME'] = 'localhost';
|
||||
$result = $this->mailer->send(
|
||||
$this->newsletter,
|
||||
$this->subscriber
|
||||
);
|
||||
//expect($result)->true();
|
||||
}
|
||||
}
|
@@ -852,7 +852,7 @@
|
||||
return 'MailPoet';
|
||||
break;
|
||||
case 'website':
|
||||
return 'WPMail';
|
||||
return 'PHPMail';
|
||||
break;
|
||||
case 'smtp':
|
||||
var method = $('#mailpoet_smtp_provider').val();
|
||||
|
Reference in New Issue
Block a user