1

I want to send all the user the reset password email, we have over 6000 user so it can't be done by hand.

I found this script from this website:

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

    // MAGENTO START
    include('app/bootstrap.php');

    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');
    $state->setAreaCode('frontend');

    $_customers = $objectManager->create('Magento\Customer\Api\AccountManagementInterface');
    $customerCollection = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
    $customerCollection->load();
    $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";
        $i++;
    }
?>

But that isn't working :(

Is there a way to make this script work or maybe another solution?

0

I printed the exception message in the code,

 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 __($exception->getMessage());
            }
            echo "<pre>";
            echo $i . " Email :-" . $email . " Mail Sent";
        $i++;

I got the error like this We received too many requests for password resets.

For this error you need to disable the password protection in magento2 backend customer configuration.

I have disabled password protection from Configuration -> Customers -> customer configuration. so it look like this in my admin,

enter image description here

set the password protection to none and try it. After the password sent, please revert back to original configuration for security purpose

  • Hi, I tried the code from you combined with the code I already had, but with no result, even no error or something. – n00bly May 2 at 7:05
  • I did something wrong, now it worked! But I have 2 mail addresses and with one I can't change it, the message is; it couldn't be saved. With the other mail address it worked. Maybe that's because of some protection? – n00bly May 2 at 7:13
  • Is that mail is different from other emails? – Jeeva Chezhiyan May 2 at 7:22
  • Is look like spam email? – Jeeva Chezhiyan May 2 at 7:22
  • I have firstname.lastname@gmail.com and firstnamelastname@gmail.com the only difference is the . (It's not marked as spam) – n00bly May 2 at 7:24

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.