Show error notice when email is sent from unauthorized email
[MAILPOET-1787]
This commit is contained in:
@@ -391,7 +391,11 @@ const StatisticsMixin = {
|
|||||||
|
|
||||||
const MailerMixin = {
|
const MailerMixin = {
|
||||||
checkMailerStatus: function checkMailerStatus(state) {
|
checkMailerStatus: function checkMailerStatus(state) {
|
||||||
if (state.meta.mta_log.error && state.meta.mta_log.status === 'paused') {
|
if (
|
||||||
|
state.meta.mta_log.error
|
||||||
|
&& state.meta.mta_log.status === 'paused'
|
||||||
|
&& state.meta.mta_log.error.operation !== 'authorization'
|
||||||
|
) {
|
||||||
const errorType = MailerMixin.getMailerErrorType(state);
|
const errorType = MailerMixin.getMailerErrorType(state);
|
||||||
MailPoet.Notice[errorType](
|
MailPoet.Notice[errorType](
|
||||||
'',
|
'',
|
||||||
|
@@ -73,6 +73,7 @@ class Menu {
|
|||||||
$this->subscribers_over_limit = $subscribers_feature->check();
|
$this->subscribers_over_limit = $subscribers_feature->check();
|
||||||
$this->checkMailPoetAPIKey();
|
$this->checkMailPoetAPIKey();
|
||||||
$this->checkPremiumKey();
|
$this->checkPremiumKey();
|
||||||
|
$this->checkFromEmailAuthorization();
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'admin_menu',
|
'admin_menu',
|
||||||
@@ -836,6 +837,13 @@ class Menu {
|
|||||||
$this->premium_key_valid = $checker->isPremiumKeyValid($show_notices);
|
$this->premium_key_valid = $checker->isPremiumKeyValid($show_notices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkFromEmailAuthorization(ServicesChecker $checker = null) {
|
||||||
|
if (self::isOnMailPoetAdminPage()) {
|
||||||
|
$checker = $checker ?: new ServicesChecker();
|
||||||
|
$checker->isFromEmailAuthorized(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getLimitPerPage($model = null) {
|
function getLimitPerPage($model = null) {
|
||||||
if ($model === null) {
|
if ($model === null) {
|
||||||
return Listing\Handler::DEFAULT_LIMIT_PER_PAGE;
|
return Listing\Handler::DEFAULT_LIMIT_PER_PAGE;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
|
use MailPoet\Mailer\MailerError;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Services\Bridge;
|
use MailPoet\Services\Bridge;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
@@ -115,4 +116,17 @@ class ServicesChecker {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isFromEmailAuthorized($display_error_notice = true) {
|
||||||
|
$mta_log_error = $this->settings->get('mta_log.error', []);
|
||||||
|
|
||||||
|
if ($mta_log_error && $mta_log_error['operation'] === MailerError::OPERATION_AUTHORIZATION) {
|
||||||
|
if ($display_error_notice) {
|
||||||
|
WPNotice::displayError($mta_log_error['error_message'], 'js-error-unauthorized-email', '', false, false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ namespace MailPoet\Mailer;
|
|||||||
class MailerError {
|
class MailerError {
|
||||||
const OPERATION_CONNECT = 'connect';
|
const OPERATION_CONNECT = 'connect';
|
||||||
const OPERATION_SEND = 'send';
|
const OPERATION_SEND = 'send';
|
||||||
|
const OPERATION_AUTHORIZATION = 'authorization';
|
||||||
|
|
||||||
const LEVEL_HARD = 'hard';
|
const LEVEL_HARD = 'hard';
|
||||||
const LEVEL_SOFT = 'soft';
|
const LEVEL_SOFT = 'soft';
|
||||||
|
@@ -22,8 +22,9 @@ class MailPoetMapper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getErrorForResult(array $result, $subscribers) {
|
function getErrorForResult(array $result, $subscribers, $sender = null) {
|
||||||
$level = MailerError::LEVEL_HARD;
|
$level = MailerError::LEVEL_HARD;
|
||||||
|
$operation = MailerError::OPERATION_SEND;
|
||||||
$retry_interval = null;
|
$retry_interval = null;
|
||||||
$subscribers_errors = [];
|
$subscribers_errors = [];
|
||||||
$result_code = !empty($result['code']) ? $result['code'] : null;
|
$result_code = !empty($result['code']) ? $result['code'] : null;
|
||||||
@@ -51,18 +52,35 @@ class MailPoetMapper {
|
|||||||
$retry_interval = self::TEMPORARY_UNAVAILABLE_RETRY_INTERVAL;
|
$retry_interval = self::TEMPORARY_UNAVAILABLE_RETRY_INTERVAL;
|
||||||
break;
|
break;
|
||||||
case API::RESPONSE_CODE_CAN_NOT_SEND:
|
case API::RESPONSE_CODE_CAN_NOT_SEND:
|
||||||
$message = Helpers::replaceLinkTags(
|
if ($result['message'] === MailerError::MESSAGE_EMAIL_NOT_AUTHORIZED) {
|
||||||
__('You currently are not permitted to send any emails with MailPoet Sending Service, which may have happened due to poor deliverability. Please [link]contact our support team[/link] to resolve the issue.', 'mailpoet'),
|
$operation = MailerError::OPERATION_AUTHORIZATION;
|
||||||
'https://www.mailpoet.com/support/',
|
$message = sprintf(__('<p>The MailPoet Sending Service did not send your latest email because the address <i>%s</i> is not yet authorized.</p>', 'mailpoet'), $sender ? $sender['from_email'] : __('Unknown address'));
|
||||||
array('target' => '_blank')
|
$message .= '<p>';
|
||||||
);
|
$message .= Helpers::replaceLinkTags(
|
||||||
|
__('[link]Authorize your email in your account now.[/link]', 'mailpoet'),
|
||||||
|
'https://account.mailpoet.com/account/authorization',
|
||||||
|
array(
|
||||||
|
'class' => 'button button-primary',
|
||||||
|
'target' => '_blank',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$message .= ' <button class="button js-button-resume-sending">' . __('Resume sending', 'mailpoet') . '</button>';
|
||||||
|
$message .= '</p>';
|
||||||
|
$message .= "<script>jQuery('.js-button-resume-sending').on('click', function() { MailPoet.Ajax.post({ api_version: window.mailpoet_api_version, endpoint: 'mailer', action: 'resumeSending' }).done(function() { jQuery('.js-error-unauthorized-email').slideUp(); MailPoet.Notice.success(MailPoet.I18n.t('mailerSendingResumedNotice')); if (window.mailpoet_listing) { window.mailpoet_listing.forceUpdate(); }}).fail(function(response) { if (response.errors.length > 0) { MailPoet.Notice.error(response.errors.map(function(error) { return error.message }), { scroll: true }); }}); })</script>";
|
||||||
|
} else {
|
||||||
|
$message = Helpers::replaceLinkTags(
|
||||||
|
__('You currently are not permitted to send any emails with MailPoet Sending Service, which may have happened due to poor deliverability. Please [link]contact our support team[/link] to resolve the issue.', 'mailpoet'),
|
||||||
|
'https://www.mailpoet.com/support/',
|
||||||
|
array('target' => '_blank')
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case API::RESPONSE_CODE_KEY_INVALID:
|
case API::RESPONSE_CODE_KEY_INVALID:
|
||||||
case API::RESPONSE_CODE_PAYLOAD_TOO_BIG:
|
case API::RESPONSE_CODE_PAYLOAD_TOO_BIG:
|
||||||
default:
|
default:
|
||||||
$message = $result['message'];
|
$message = $result['message'];
|
||||||
}
|
}
|
||||||
return new MailerError(MailerError::OPERATION_SEND, $level, $message, $retry_interval, $subscribers_errors);
|
return new MailerError($operation, $level, $message, $retry_interval, $subscribers_errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSubscribersErrors($result_parsed, $subscribers) {
|
private function getSubscribersErrors($result_parsed, $subscribers) {
|
||||||
|
@@ -51,7 +51,7 @@ class MailPoet {
|
|||||||
if (!empty($result['code']) && $result['code'] === API::RESPONSE_CODE_KEY_INVALID) {
|
if (!empty($result['code']) && $result['code'] === API::RESPONSE_CODE_KEY_INVALID) {
|
||||||
Bridge::invalidateKey();
|
Bridge::invalidateKey();
|
||||||
}
|
}
|
||||||
return $this->error_mapper->getErrorForResult($result, $subscriber);
|
return $this->error_mapper->getErrorForResult($result, $subscriber, $this->sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processSubscriber($subscriber) {
|
function processSubscriber($subscriber) {
|
||||||
|
@@ -12,6 +12,7 @@ class Notice {
|
|||||||
private $message;
|
private $message;
|
||||||
private $classes;
|
private $classes;
|
||||||
private $data_notice_name;
|
private $data_notice_name;
|
||||||
|
private $render_in_paragraph;
|
||||||
|
|
||||||
function __construct($type, $message, $classes = '', $data_notice_name = '', $render_in_paragraph = true) {
|
function __construct($type, $message, $classes = '', $data_notice_name = '', $render_in_paragraph = true) {
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
@@ -68,7 +68,7 @@ class MailPoetMapperTest extends \MailPoetTest {
|
|||||||
$error = $this->mapper->getErrorForResult($api_result, $this->subscribers);
|
$error = $this->mapper->getErrorForResult($api_result, $this->subscribers);
|
||||||
|
|
||||||
expect($error)->isInstanceOf(MailerError::class);
|
expect($error)->isInstanceOf(MailerError::class);
|
||||||
expect($error->getOperation())->equals(MailerError::OPERATION_SEND);
|
expect($error->getOperation())->equals(MailerError::OPERATION_AUTHORIZATION);
|
||||||
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||||
expect($error->getMessage())->contains('The MailPoet Sending Service did not send your latest email because the address');
|
expect($error->getMessage())->contains('The MailPoet Sending Service did not send your latest email because the address');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user