We have migrated 60,000 Customers from Old System to Magento.

Now we have to send them Email for Reset Password.



I have gone through above links, but it will be for Magento 1.

How to send Reset Password Email Programmatically. Need to use MailChimp for this Mass Email Sending or by GMAIL SMTP?

Need to create Cron Job? Bulk Mail Send Goes to Spam?

This Script is going to run One time only.

2 Answers 2


From Outside Magento.

If you want to send All Customers Reset Password Email, then below is the code.

//place this before any script you want to calculate time
$time_start = microtime(true);


use Magento\Framework\App\Bootstrap;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\AccountManagement;

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');

$_customers = $objectManager->create('Magento\Customer\Api\AccountManagementInterface');
$customerCollection = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
$i = 0;
foreach ($customerCollection as $customers) {

    $email = $customers->getData('email');

    try {
            $_customers->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
        } catch (NoSuchEntityException $e) {
            // Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
        } catch (\Exception $exception) {
            echo __('We\'re unable to send the password reset email.');
        echo "<pre>";
        echo $i . " Email :-" . $email . " Mail Sent";

echo "<pre>";
echo "Total Customers: " . $i;

$time_end = microtime(true);

//dividing with 60 will give the execution time in minutes other wise seconds
$execution_time = ($time_end - $time_start) / 60;

//execution time of the script
echo "<pre>";
echo 'Total Execution Time:</b> ' . $execution_time . ' Mins';

Hope it helps Magento Community :)

  • I have tried this code in Cron it gives me this error [2019-06-19 11:29:46] main.ERROR: Cron Job gme_alerttest_cron has an error: No such entity with email = [email protected], websiteId = 0. Statistics: {"sum":0,"count":1,"realmem":0,"emalloc":0,"realmem_start":81788928,"emalloc_start":77602808} [] []
    – Ghulam.M
    Commented Jun 19, 2019 at 11:33

You can try below code for sending forgot/reset password emails.

public function __construct(
    Magento\Framework\App\Action\Context $context,
    Magento\Customer\Model\Session $customerSession,
    Magento\Customer\Api\AccountManagementInterface $customerAccountManagement,
) {
    $this->session = $customerSession;
    $this->customerAccountManagement = $customerAccountManagement;

public function sendCustomMail()

            $email = '[email protected]'; // loop your email.

            if (!\Zend_Validate::is($email, 'EmailAddress')) {
                $this->messageManager->addErrorMessage(__('Please correct the email address.'));

            try {
            } catch (NoSuchEntityException $e) {
                // Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
            } catch (\Exception $exception) {
                    __('We\'re unable to send the password reset email.')

Make sure it should extend \Magento\Customer\Controller\AbstractAccount You can take the reference of /vendor/magento/module-customer/Controller/Account/ForgotPasswordPost.php.

Prepare the code accordingly. Hope it helps.

  • 1
    Base I Know. Need to Create Cron Job? Bulk Mail goes to Spam?
    – Jackson
    Commented Nov 2, 2016 at 4:54
  • Get the customer collection and make it as a loop and send it accordingly. Commented Nov 2, 2016 at 6:14

Your Answer

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

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