diff --git a/lib/Subscribers/ConfirmationEmailMailer.php b/lib/Subscribers/ConfirmationEmailMailer.php index 4186d86545..ada8aa188e 100644 --- a/lib/Subscribers/ConfirmationEmailMailer.php +++ b/lib/Subscribers/ConfirmationEmailMailer.php @@ -6,6 +6,7 @@ use Html2Text\Html2Text; use MailPoet\Mailer\Mailer; use MailPoet\Mailer\MailerError; use MailPoet\Models\Subscriber; +use MailPoet\Services\Bridge; use MailPoet\Settings\SettingsController; use MailPoet\Subscription\Url; use MailPoet\Util\Helpers; @@ -52,6 +53,12 @@ class ConfirmationEmailMailer { return false; } + $authorization_emails_validation = $this->settings->get(Bridge::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING_NAME); + $unauthorized_confirmation_email = isset($authorization_emails_validation['invalid_confirmation_address']); + if (Bridge::isMPSendingServiceEnabled() && $unauthorized_confirmation_email) { + return false; + } + $segments = $subscriber->segments()->findMany(); $segment_names = array_map(function($segment) { return $segment->name; diff --git a/tests/integration/Subscribers/ConfirmationEmailMailerTest.php b/tests/integration/Subscribers/ConfirmationEmailMailerTest.php index 7da8eee5e7..e6814f7a6e 100644 --- a/tests/integration/Subscribers/ConfirmationEmailMailerTest.php +++ b/tests/integration/Subscribers/ConfirmationEmailMailerTest.php @@ -8,6 +8,8 @@ use MailPoet\Mailer\Mailer; use MailPoet\Models\Segment; use MailPoet\Models\Subscriber; use MailPoet\Models\SubscriberSegment; +use MailPoet\Services\Bridge; +use MailPoet\Settings\SettingsController; use MailPoet\WP\Functions as WPFunctions; class ConfirmationEmailMailerTest extends \MailPoetTest { @@ -69,6 +71,28 @@ class ConfirmationEmailMailerTest extends \MailPoetTest { expect($subscriber->getErrors()[0])->equals('send error'); } + function testItDoesntSendWhenMSSIsActiveAndConfirmationEmailIsNotAuthorized() { + $subscriber = Subscriber::create(); + $subscriber->hydrate([ + 'first_name' => 'John', + 'last_name' => 'Mailer', + 'email' => 'john@mailpoet.com' + ]); + + $mailer = $this->makeEmpty(Mailer::class, [ + 'send' => Stub\Expected::never(), + ]); + + $settings = new SettingsController; + $settings->set(Bridge::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING_NAME, ['invalid_confirmation_address' => 'email@email.com']); + $settings->set(Mailer::MAILER_CONFIG_SETTING_NAME, ['method' => Mailer::METHOD_MAILPOET]); + $sender = new ConfirmationEmailMailer($mailer); + + $result = $sender->sendConfirmationEmail($subscriber); + expect($result)->equals(false); + $settings->set(Bridge::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING_NAME, null); + } + function testItLimitsNumberOfConfirmationEmailsForNotLoggedInUser() { wp_set_current_user(0); expect((new WPFunctions)->isUserLoggedIn())->false();