5

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.

3
  • Why you wanna do that?
    – Jackson
    Oct 5, 2016 at 10:23
  • That should help you: stackoverflow.com/questions/16996673/… Oct 5, 2016 at 10:28
  • @RaphaelatDigitalPianism vendor\magento\module-customer\etc\config.xml What will happen if i comment <email_no_password_template>customer_create_account_email_no_password_template</email_no_password_template> ? Can't do?
    – Jackson
    Oct 5, 2016 at 10:44

2 Answers 2

12

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;
    }
}
5
  • What if i want to send email from my Store1 and not from Store2?
    – Hardik
    Apr 12, 2018 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, 2018 at 1:49
  • Did you got the solution for this?
    – Avesh Naik
    Nov 25, 2019 at 10:22
  • 1
    return $subject; could just be return;, for saving memory.
    – Key Shang
    Jul 14, 2020 at 8:19
  • Please note that this will disable the email confirmation emails too.
    – AboElnouR
    Jun 9, 2022 at 21:05
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.

1
  • 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. Dec 23, 2017 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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