Magento – Magento 2: How to send different registration mail for different customer group

email-templatesmagento2

I am using magento 2.1 and i want to send the different registration emails or send different content, like separate login link for the customer belongs to different customer group. How can i achieve it. Please help.

Best Answer

First rewite below file vendor/magento/module-customer/Model/AccountManagement.php

Find below code from file

Function is :

  protected function sendNewAccountEmail(
    $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
    );

    return $this;
}

and change

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