Allow user send with any email address from verified domain
MAILPOET-4601
This commit is contained in:
committed by
Aschepikov
parent
bb42da6a87
commit
bd7da6b28c
@ -22,6 +22,8 @@ import { fromUrl } from 'common/thumbnail.ts';
|
||||
|
||||
import { GlobalContext } from 'context/index.jsx';
|
||||
|
||||
import { extractEmailDomain } from 'common/functions';
|
||||
|
||||
const automaticEmails = window.mailpoet_woocommerce_automatic_emails || [];
|
||||
|
||||
const generateGaTrackingCampaignName = (id, subject) => {
|
||||
@ -168,6 +170,12 @@ class NewsletterSendComponent extends Component {
|
||||
if (window.mailpoet_mta_method !== 'MailPoet') {
|
||||
return true;
|
||||
}
|
||||
const verifiedDomains = await this.loadVerifiedSenderDomains();
|
||||
const senderDomain = extractEmailDomain(this.state.item.sender_address);
|
||||
if (verifiedDomains.indexOf(senderDomain) !== -1) {
|
||||
// allow user send with any email address from verified domain
|
||||
return true;
|
||||
}
|
||||
const addresses = await this.loadAuthorizedEmailAddresses();
|
||||
const fromAddress = this.state.item.sender_address;
|
||||
return addresses.indexOf(fromAddress) !== -1;
|
||||
@ -275,6 +283,18 @@ class NewsletterSendComponent extends Component {
|
||||
return authorizedEmails;
|
||||
};
|
||||
|
||||
loadVerifiedSenderDomains = async () => {
|
||||
if (window.mailpoet_mta_method !== 'MailPoet') {
|
||||
return [];
|
||||
}
|
||||
const response = await MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'mailer',
|
||||
action: 'getVerifiedSenderDomains',
|
||||
});
|
||||
return response.data || [];
|
||||
};
|
||||
|
||||
handleSend = (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
@ -9,6 +9,7 @@ use MailPoet\Mailer\MailerFactory;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Mailer\MetaInfo;
|
||||
use MailPoet\Services\AuthorizedEmailsController;
|
||||
use MailPoet\Services\AuthorizedSenderDomainController;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
|
||||
@ -29,6 +30,9 @@ class Mailer extends APIEndpoint {
|
||||
/** @var MailerFactory */
|
||||
private $mailerFactory;
|
||||
|
||||
/** @var AuthorizedSenderDomainController */
|
||||
private $senderDomainController;
|
||||
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
|
||||
];
|
||||
@ -38,13 +42,15 @@ class Mailer extends APIEndpoint {
|
||||
SettingsController $settings,
|
||||
Bridge $bridge,
|
||||
MailerFactory $mailerFactory,
|
||||
MetaInfo $mailerMetaInfo
|
||||
MetaInfo $mailerMetaInfo,
|
||||
AuthorizedSenderDomainController $senderDomainController
|
||||
) {
|
||||
$this->authorizedEmailsController = $authorizedEmailsController;
|
||||
$this->settings = $settings;
|
||||
$this->bridge = $bridge;
|
||||
$this->mailerFactory = $mailerFactory;
|
||||
$this->mailerMetaInfo = $mailerMetaInfo;
|
||||
$this->senderDomainController = $senderDomainController;
|
||||
}
|
||||
|
||||
public function send($data = []) {
|
||||
@ -89,4 +95,9 @@ class Mailer extends APIEndpoint {
|
||||
$authorizedEmails = $this->bridge->getAuthorizedEmailAddresses();
|
||||
return $this->successResponse($authorizedEmails);
|
||||
}
|
||||
|
||||
public function getVerifiedSenderDomains() {
|
||||
$verifiedDomains = $this->senderDomainController->getVerifiedSenderDomains();
|
||||
return $this->successResponse($verifiedDomains);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user