1

What is the right approach to disable Welcome Email after completes registration process. I'm using magento2.1. We have an integration with a customer management system and which will sent email to customer after registration. So we need to disable customer welcome email sent by Magento.

I created a custom module to disable mail communication. di.xml

<type name="\Magento\Customer\Model\Customer">
        <plugin name="disable-email-confirmation" type="Company\Customer\Model\Plugin\Customer" sortOrder="1"/>
    </type>
</xml>

Model/Plugin/Customer.php

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Company\Customer\Model\Plugin;

class Customer
{
    public function aroundSendNewAccountEmail(\Magento\Customer\Model\Customer $subject, \Closure $proceed)
    {  
        //$result = $proceed(); 

        return $subject;
    }
} 

This is not working. I'm still getting emails. I see some email communcation refereces inside AccountManagementInterface.

7

Create a plugin for \Magento\Customer\Model\EmailNotification. Update di.xml

<type name="\Magento\Customer\Model\EmailNotification">
    <plugin name="disable-email-notification" type="Module\Model\Plugin\EmailNotification" sortOrder="1"/>
</type>

then create the plugin

class EmailNotification
{
    public function aroundNewAccount(\Magento\Customer\Model\EmailNotification $subject, \Closure $proceed)
    {
        return $subject;
    }
}
  • What if i want to send email from my Store1 and not from Store2? – Hardik Apr 12 '18 at 9:34
  • Hi, Thanks, Here How can I check if customer group. I want set condition on customer group. If customer are retailer we are not sending email. – Ravi Soni Oct 3 '18 at 1:49
0

You can override below file to disable it.

vendor/magento/module-customer/Model/EmailNotification.php

Look for below function in it.

public function newAccount(
    CustomerInterface $customer,
    $type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
    $backUrl = '',
    $storeId = 0,
    $sendemailStoreId = null
) {
    $types = $this->getTemplateTypes();

    if (!isset($types[$type])) {
        throw new LocalizedException(__('Please correct the transactional account email type.'));
    }

    if (!$storeId) {
        $storeId = $this->getWebsiteStoreId($customer, $sendemailStoreId);
    }

    $store = $this->storeManager->getStore($customer->getStoreId());

    $customerEmailData = $this->getFullCustomerObject($customer);

    $this->sendEmailTemplate(
        $customer,
        $types[$type],
        self::XML_PATH_REGISTER_EMAIL_IDENTITY,
        ['customer' => $customerEmailData, 'back_url' => $backUrl, 'store' => $store],
        $storeId
    ); 
}

Than comment out lines which are used to send mail.

/*$this->sendEmailTemplate(
        $customer,
        $types[$type],
        self::XML_PATH_REGISTER_EMAIL_IDENTITY,
        ['customer' => $customerEmailData, 'back_url' => $backUrl, 'store' => $store],
        $storeId
    );*/

Clear cache and check.

  • This is not possible. Because most of propertiesused in this function have orive access. I think create around plugin will be much better. Or just override this method with epty body. – Stepan Furman Dec 23 '17 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.