diff --git a/mailpoet/assets/js/src/listing/notices.jsx b/mailpoet/assets/js/src/listing/notices.jsx index aaffc339a1..5c1b5a628f 100644 --- a/mailpoet/assets/js/src/listing/notices.jsx +++ b/mailpoet/assets/js/src/listing/notices.jsx @@ -72,12 +72,33 @@ export function MailerError(props) { links[match], 'text/xml', ).firstChild; + + const listOfAttributeNames = link.getAttributeNames(); + const allowedAttributesList = [ + 'target', + 'rel', + 'class', + 'data-email', + 'data-type', + ]; + + // include these custom attributes in the final link + const otherAttributes = listOfAttributeNames.reduce((acc, name) => { + if (allowedAttributesList.includes(name)) { + // react requires the class attribute to be named className. + return { + ...acc, + [name === 'class' ? 'className' : name]: link.getAttribute(name), + }; + } + return { ...acc }; + }, {}); + return ( {link.textContent} diff --git a/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php b/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php index 0ceefb1e4f..7fbe8ec2b8 100644 --- a/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php +++ b/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php @@ -23,6 +23,8 @@ class MailPoetMapper { const METHOD = Mailer::METHOD_MAILPOET; const TEMPORARY_UNAVAILABLE_RETRY_INTERVAL = 300; // seconds + // Bridge message from https://github.com/mailpoet/services-bridge/blob/a3fbf0c1a88abc77840f9ec9f3965e632ce7d8b5/api/messages.rb#L16 + const MAILPOET_BRIDGE_DMRAC_ERROR = "Email violates Sender Domain's DMARC policy. Please set up sender authentication."; /** @var Bridge */ private $bridge; @@ -76,7 +78,11 @@ class MailPoetMapper { $resultParsed = json_decode($result['message'], true); $message = __('Error while sending.', 'mailpoet'); if (!is_array($resultParsed)) { - $message .= ' ' . $result['message']; + if ($result['message'] === self::MAILPOET_BRIDGE_DMRAC_ERROR) { + $message .= $this->getDmarcMessage($result, $sender); + } else { + $message .= ' ' . $result['message']; + } break; } try { @@ -178,6 +184,25 @@ class MailPoetMapper { return "{$message}
"; } + private function getDmarcMessage($result, $sender): string { + $messageToAppend = __('[link1]Click here to start the authentication[/link1].', 'mailpoet'); + $senderEmail = $sender['from_email'] ?? ''; + + $appendMessage = Helpers::replaceLinkTags( + $messageToAppend, + '#', + [ + 'class' => 'mailpoet-js-button-authorize-email-and-sender-domain', + 'data-email' => $senderEmail, + 'data-type' => 'domain', + 'rel' => 'noopener noreferrer', + ], + 'link1' + ); + $final = ' ' . $result['message'] . ' ' . $appendMessage; + return $final; + } + private function getEmailVolumeLimitReachedMessage(): string { $partialApiKey = $this->servicesChecker->generatePartialApiKey(); $emailVolumeLimit = $this->subscribersFeature->getEmailVolumeLimit();