I would like to be able to invoke an API that resends a confirmation email to a user --- the same way I can do through the mailpoet subscribers page.
The use case is a user subscribes to a newsletter, and tries to sign up again. Since they are an existing user I would like the ability to resend the confirmation email programmatically.
I have made a patch that exposes sendConfirmationEmail as a published API. If you would integrate it everyone else could benefit and I wouldn't have to maintain it myself.
diff --git a/mailpoet/lib/API/MP/v1/API.php b/mailpoet/lib/API/MP/v1/API.php
index 04b14d2b9..d620f2d8a 100644
--- a/mailpoet/lib/API/MP/v1/API.php
+++ b/mailpoet/lib/API/MP/v1/API.php
@@ -100,6 +100,10 @@ class API {
return $this->subscribers->getSubscribersCount($filter);
}
+ public function sendConfirmationEmail($subscriberId) {
+ return $this->subscribers->sendConfirmationEmail($subscriberId);
+ }
+
public function isSetupComplete() {
return !(
$this->changelog->shouldShowWelcomeWizard()
diff --git a/mailpoet/lib/API/MP/v1/Subscribers.php b/mailpoet/lib/API/MP/v1/Subscribers.php
index 40230ecc3..4d0a99013 100644
--- a/mailpoet/lib/API/MP/v1/Subscribers.php
+++ b/mailpoet/lib/API/MP/v1/Subscribers.php
@@ -253,6 +253,30 @@ class Subscribers {
return $this->subscriberListingRepository->getCount($listingDefinition);
}
+ /**
+ * @throws APIException
+ */
+ public function sendConfirmationEmail($subscriberId) {
+ $subscriber = $this->subscribersRepository->findOneById($subscriberId);
+ if ($subscriber instanceof SubscriberEntity) {
+ try {
+ if ($this->confirmationEmailMailer->sendConfirmationEmail($subscriber)) {
+ return;
+ } else {
+ throw new APIException(
+ sprintf(__('Confirmation email failed to send: %s', 'mailpoet'),
+ APIException::CONFIRMATION_FAILED_TO_SEND));
+ }
+ } catch (\Exception $e) {
+ throw new APIException(
+ sprintf(__('Confirmation email failed to send: %s', 'mailpoet'), strtolower($e->getMessage())),
+ APIException::CONFIRMATION_FAILED_TO_SEND);
+ }
+ } else {
+ throw new APIException(__('The subscriber does not exist.', 'mailpoet'), APIException::SUBSCRIBER_NOT_EXISTS);
+ }
+ }
+
/**
* @param array $filter {
* Filters to retrieve subscribers.