Improve the DMARC error message

When the DMARC error message is displayed, add the sentence Click here to start the authentication. This will be a link that opens the verify domain dialogue

MAILPOET-4311
This commit is contained in:
Oluwaseun Olorunsola
2022-07-24 16:17:42 +01:00
committed by Veljko V
parent f97ca0e11e
commit c1f5ddf96e
2 changed files with 49 additions and 3 deletions

View File

@ -72,12 +72,33 @@ export function MailerError(props) {
links[match], links[match],
'text/xml', 'text/xml',
).firstChild; ).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 ( return (
<a <a
key={`a-${match}`} key={`a-${match}`}
href={link.getAttribute('href')} href={link.getAttribute('href')}
target={link.getAttribute('target')} {...otherAttributes}
rel={link.getAttribute('rel')}
> >
{link.textContent} {link.textContent}
</a> </a>

View File

@ -23,6 +23,8 @@ class MailPoetMapper {
const METHOD = Mailer::METHOD_MAILPOET; const METHOD = Mailer::METHOD_MAILPOET;
const TEMPORARY_UNAVAILABLE_RETRY_INTERVAL = 300; // seconds 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 */ /** @var Bridge */
private $bridge; private $bridge;
@ -76,7 +78,11 @@ class MailPoetMapper {
$resultParsed = json_decode($result['message'], true); $resultParsed = json_decode($result['message'], true);
$message = __('Error while sending.', 'mailpoet'); $message = __('Error while sending.', 'mailpoet');
if (!is_array($resultParsed)) { 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; break;
} }
try { try {
@ -178,6 +184,25 @@ class MailPoetMapper {
return "{$message}<br/>"; return "{$message}<br/>";
} }
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 { private function getEmailVolumeLimitReachedMessage(): string {
$partialApiKey = $this->servicesChecker->generatePartialApiKey(); $partialApiKey = $this->servicesChecker->generatePartialApiKey();
$emailVolumeLimit = $this->subscribersFeature->getEmailVolumeLimit(); $emailVolumeLimit = $this->subscribersFeature->getEmailVolumeLimit();