diff --git a/composer.json b/composer.json index bebbb79678..7091ac4db1 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "cerdic/css-tidy": "*", "sunra/php-simple-html-dom-parser": "*", "tburry/pquery": "*", - "j4mie/paris": "1.5.4" + "j4mie/paris": "1.5.4", + "swiftmailer/swiftmailer": "^5.4" }, "require-dev": { "codeception/codeception": "*", diff --git a/composer.lock b/composer.lock index 68c1b5a11b..275a14b621 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "0e2b177a6de46c3a1263386f1b803faf", - "content-hash": "a8f94cd2f301434c7bac1f383d9f975f", + "hash": "8c4bd23de3a24fd6cb46185e6ea8c8ba", "packages": [ { "name": "cerdic/css-tidy", @@ -261,6 +260,59 @@ ], "time": "2013-05-04 14:32:03" }, + { + "name": "swiftmailer/swiftmailer", + "version": "v5.4.1", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/0697e6aa65c83edf97bb0f23d8763f94e3f11421", + "reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "mockery/mockery": "~0.9.1,<0.9.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.4-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Corbyn" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.org", + "keywords": [ + "email", + "mail", + "mailer" + ], + "time": "2015-06-06 14:19:39" + }, { "name": "tburry/pquery", "version": "v1.1.0", @@ -378,23 +430,23 @@ "packages-dev": [ { "name": "codeception/codeception", - "version": "2.1.3", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/Codeception/Codeception.git", - "reference": "cd810cb78a869408602e17271f9b7368b09a7ca8" + "reference": "521adbb2ee34e9debdd8508a2c41ab2b5c2f042b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeception/Codeception/zipball/cd810cb78a869408602e17271f9b7368b09a7ca8", - "reference": "cd810cb78a869408602e17271f9b7368b09a7ca8", + "url": "https://api.github.com/repos/Codeception/Codeception/zipball/521adbb2ee34e9debdd8508a2c41ab2b5c2f042b", + "reference": "521adbb2ee34e9debdd8508a2c41ab2b5c2f042b", "shasum": "" }, "require": { "ext-json": "*", "ext-mbstring": "*", "facebook/webdriver": ">=1.0.1", - "guzzlehttp/guzzle": ">=4.1.4 <7.0", + "guzzlehttp/guzzle": ">=4.0|<7.0", "guzzlehttp/psr7": "~1.0", "php": ">=5.4.0", "phpunit/phpunit": "~4.8.0", @@ -454,7 +506,7 @@ "functional testing", "unit testing" ], - "time": "2015-10-02 09:38:59" + "time": "2015-08-09 13:48:55" }, { "name": "codeception/verify", @@ -981,16 +1033,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.2.4", + "version": "2.2.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef1ca6835468857944d5c3b48fa503d5554cff2f", + "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f", "shasum": "" }, "require": { @@ -1039,7 +1091,7 @@ "testing", "xunit" ], - "time": "2015-10-06 15:47:00" + "time": "2015-09-14 06:51:16" }, { "name": "phpunit/php-file-iterator", @@ -1221,16 +1273,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.11", + "version": "4.8.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "bdd199472410fd7e32751f9c814c7e06f2c21bd5" + "reference": "73fad41adb5b7bc3a494bb930d90648df1d5e74b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bdd199472410fd7e32751f9c814c7e06f2c21bd5", - "reference": "bdd199472410fd7e32751f9c814c7e06f2c21bd5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/73fad41adb5b7bc3a494bb930d90648df1d5e74b", + "reference": "73fad41adb5b7bc3a494bb930d90648df1d5e74b", "shasum": "" }, "require": { @@ -1289,20 +1341,20 @@ "testing", "xunit" ], - "time": "2015-10-07 10:39:46" + "time": "2015-09-20 12:56:44" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", + "version": "2.3.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" + "reference": "5e2645ad49d196e020b85598d7c97e482725786a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5e2645ad49d196e020b85598d7c97e482725786a", + "reference": "5e2645ad49d196e020b85598d7c97e482725786a", "shasum": "" }, "require": { @@ -1345,7 +1397,7 @@ "mock", "xunit" ], - "time": "2015-10-02 06:51:40" + "time": "2015-08-19 09:14:08" }, { "name": "psr/http-message", @@ -1681,16 +1733,16 @@ }, { "name": "sebastian/global-state", - "version": "1.1.0", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97" + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23af31f402993cfd94e99cbc4b782e9a78eb0e97", - "reference": "23af31f402993cfd94e99cbc4b782e9a78eb0e97", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", "shasum": "" }, "require": { @@ -1728,7 +1780,7 @@ "keywords": [ "global state" ], - "time": "2015-06-21 15:11:22" + "time": "2014-10-06 09:23:50" }, { "name": "sebastian/recursion-context", diff --git a/lib/Router/Mailer.php b/lib/Router/Mailer.php index fe6cc2d1ac..941773d25d 100644 --- a/lib/Router/Mailer.php +++ b/lib/Router/Mailer.php @@ -34,6 +34,9 @@ class Mailer { case 'SendGrid': $mailer = new $this->mailer['class']($this->mailer['api_key'], $this->fromEmail, $this->fromName); break; + case 'SMTP': + $mailer = new $this->mailer['class']($this->mailer['host'], $this->mailer['port'], $this->mailer['authentication'], $this->mailer['encryption'], $this->fromEmail, $this->fromName); + break; } return $mailer; } @@ -42,7 +45,7 @@ class Mailer { if(!is_array($subscriber)) return $subscriber; $first_name = (isset($subscriber['first_name'])) ? $subscriber['first_name'] : ''; $last_name = (isset($subscriber['last_name'])) ? $subscriber['last_name'] : ''; - if (!$first_name && !$last_name) return $subscriber['email']; + if(!$first_name && !$last_name) return $subscriber['email']; $subscriber = sprintf('%s %s <%s>', $first_name, $last_name, $subscriber['email']); $subscriber = trim(preg_replace('!\s\s+!', ' ', $subscriber)); return $subscriber; @@ -78,13 +81,24 @@ class Mailer { 'name' => 'SendGrid', 'type' => 'API', 'api_key' => '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' + ), + array( + 'name' => 'SMTP', + 'type' => 'SMTP', + 'host' => 'email-smtp.us-west-2.amazonaws.com', + 'port' => 587, + 'authentication' => array( + 'login' => 'AKIAIGPBLH6JWG5VCBQQ', + 'password' => 'AudVHXHaYkvr54veCzqiqOxDiMMyfQW3/V6F1tYzGXY3' + ), + 'encryption' => 'tls' ) ); $mailer = $mailers[array_rand($mailers)]; return array_merge($mailer, array('class' => sprintf('MailPoet\\Mailer\\%s\\%s', $mailer['type'], $mailer['name']))); } if($setting === 'from_name') return 'Sender'; - if($setting === 'from_address') return 'mailpoet-phoenix-test@mailinator.com'; + if($setting === 'from_address') return 'staff@mailpoet.com'; return Setting::where('name', $setting) ->findOne()->value; } diff --git a/tests/unit/Mailer/API/ElasticEmailCest.php b/tests/unit/Mailer/API/ElasticEmailCest.php index 094a4957ed..8d343cfcd6 100644 --- a/tests/unit/Mailer/API/ElasticEmailCest.php +++ b/tests/unit/Mailer/API/ElasticEmailCest.php @@ -9,7 +9,7 @@ class ElasticEmailCest { 'type' => 'API', 'api_key' => '997f1f7f-41de-4d7f-a8cb-86c8481370fa' ); - $this->fromEmail = 'do-not-reply@mailpoet.com'; + $this->fromEmail = 'staff@mailpoet.com'; $this->fromName = 'Sender'; $this->mailer = new ElasticEmail($this->settings['api_key'], $this->fromEmail, $this->fromName); $this->mailer->subscriber = 'Recipient '; diff --git a/tests/unit/Mailer/API/MailGunCest.php b/tests/unit/Mailer/API/MailGunCest.php index 9e5b0e7229..fda171ace4 100644 --- a/tests/unit/Mailer/API/MailGunCest.php +++ b/tests/unit/Mailer/API/MailGunCest.php @@ -10,7 +10,7 @@ class MailGunCest { 'api_key' => 'key-6cf5g5qjzenk-7nodj44gdt8phe6vam2', 'domain' => 'mrcasual.com' ); - $this->from = 'Sender '; + $this->from = 'Sender '; $this->mailer = new MailGun($this->settings['domain'], $this->settings['api_key'], $this->from); $this->mailer->subscriber = 'Recipient '; $this->mailer->newsletter = array( diff --git a/tests/unit/Mailer/API/MandrillCest.php b/tests/unit/Mailer/API/MandrillCest.php index 51b5db0ea2..254a22918f 100644 --- a/tests/unit/Mailer/API/MandrillCest.php +++ b/tests/unit/Mailer/API/MandrillCest.php @@ -9,7 +9,7 @@ class MandrillCest { 'type' => 'API', 'api_key' => '692ys1B7REEoZN7R-dYwNA' ); - $this->fromEmail = 'do-not-reply@mailpoet.com'; + $this->fromEmail = 'staff@mailpoet.com'; $this->fromName = 'Sender'; $this->mailer = new Mandrill($this->settings['api_key'], $this->fromEmail, $this->fromName); $this->mailer->subscriber = 'Recipient '; @@ -60,6 +60,30 @@ class MandrillCest { ->equals(json_encode($this->mailer->getBody())); } + function itCanProcessSubscriber() { + expect($this->mailer->processSubscriber('test@test.com')) + ->equals(array( + array( + 'email' => 'test@test.com', + 'name' => '' + ) + )); + expect($this->mailer->processSubscriber('First ')) + ->equals(array( + array( + 'email' => 'test@test.com', + 'name' => 'First' + ) + )); + expect($this->mailer->processSubscriber('First Last ')) + ->equals(array( + array( + 'email' => 'test@test.com', + 'name' => 'First Last' + ) + )); + } + function itCannotSendWithoutProperAPIKey() { $mailer = clone $this->mailer; $mailer->api_key = 'someapi'; diff --git a/tests/unit/Mailer/API/SendGridCest.php b/tests/unit/Mailer/API/SendGridCest.php index f3752db18b..9eff21652f 100644 --- a/tests/unit/Mailer/API/SendGridCest.php +++ b/tests/unit/Mailer/API/SendGridCest.php @@ -9,7 +9,7 @@ class SendGridCest { 'type' => 'API', 'api_key' => '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' ); - $this->fromEmail = 'do-not-reply@mailpoet.com'; + $this->fromEmail = 'staff@mailpoet.com'; $this->fromName = 'Sender'; $this->mailer = new SendGrid($this->settings['api_key'], $this->fromEmail, $this->fromName); $this->mailer->subscriber = 'Recipient '; diff --git a/tests/unit/Mailer/SMTP/SMTPCest.php b/tests/unit/Mailer/SMTP/SMTPCest.php new file mode 100644 index 0000000000..1aedf6a4c1 --- /dev/null +++ b/tests/unit/Mailer/SMTP/SMTPCest.php @@ -0,0 +1,91 @@ +settings = array( + 'name' => 'SMTP', + 'type' => 'SMTP', + 'host' => 'email-smtp.us-west-2.amazonaws.com', + 'port' => 587, + 'authentication' => array( + 'login' => 'AKIAIGPBLH6JWG5VCBQQ', + 'password' => 'AudVHXHaYkvr54veCzqiqOxDiMMyfQW3/V6F1tYzGXY3' + ), + 'encryption' => 'tls' + ); + $this->fromEmail = 'staff@mailpoet.com'; + $this->fromName = 'Sender'; + $this->mailer = new SMTP($this->settings['host'], $this->settings['port'], $this->settings['authentication'], $this->settings['encryption'], $this->fromEmail, $this->fromName); + $this->subscriber = 'Recipient '; + $this->newsletter = array( + 'subject' => 'testing SMTP', + 'body' => array( + 'html' => 'HTML body', + 'text' => 'TEXT body' + ) + ); + } + + function itCanBuildMailer() { + $mailer = $this->mailer->buildMailer(); + expect($mailer->getTransport() + ->getHost()) + ->equals($this->settings['host']); + expect($mailer->getTransport() + ->getPort()) + ->equals($this->settings['port']); + expect($mailer->getTransport() + ->getUsername()) + ->equals($this->settings['authentication']['login']); + expect($mailer->getTransport() + ->getPassword()) + ->equals($this->settings['authentication']['password']); + expect($mailer->getTransport() + ->getEncryption()) + ->equals($this->settings['encryption']); + } + + 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->fromEmail => $this->fromName)); + 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 ')) + ->equals(array('test@test.com' => 'First')); + expect($this->mailer->processSubscriber('First Last ')) + ->equals(array('test@test.com' => 'First Last')); + } + + function itCantSentWithoutProperAuthentication() { + $mailer = clone $this->mailer; + $mailer->smtpAuthentication['login'] = 'someone'; + $mailer->mailer = $mailer->buildMailer(); + $result = $mailer->send( + $this->newsletter, + $this->subscriber + ); + expect($result)->false(); + } + + function itCanSend() { + $result = $this->mailer->send( + $this->newsletter, + $this->subscriber + ); + expect($result)->true(); + } +} diff --git a/tests/unit/Router/MailerCest.php b/tests/unit/Router/MailerCest.php index 0f76693c09..15a18d91aa 100644 --- a/tests/unit/Router/MailerCest.php +++ b/tests/unit/Router/MailerCest.php @@ -8,7 +8,7 @@ class MailerCest { } function itCanConstruct() { - expect($this->router->from)->equals('Sender '); + expect($this->router->from)->equals('Sender '); } function itCanTransformSubscriber() {