0

I have tried below code to send all customer reset password link

    <?php

namespace Vendor\Module\Cron;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\AccountManagement;
class Mail
{   
        /**
    * @var \Psr\Log\LoggerInterface
    */
    private $_logger;

    protected $customerAccountManagement;

    public function __construct(
        \Psr\Log\LoggerInterface $logger,
        \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface,
        \Magento\Customer\Model\Customer $customer,
        AccountManagementInterface $customerAccountManagement
    )
    {
        $this->_logger = $logger;
        $this->_customer = $customer;
        $this->customerRepositoryInterface=$customerRepositoryInterface;
        $this->customerAccountManagement = $customerAccountManagement;
    }

    /**
    * Execute the cron
    *
    * @return void
    */
    public function execute()
    {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/cron.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info(__METHOD__);  

        $customer = $this->_customer->getCollection();
        foreach ($customer as $Cust) {
                                       $this->customerAccountManagement->initiatePasswordReset(
                    $Cust->getEmail(),
                    AccountManagement::EMAIL_RESET
                );


                $this->_logger->info(' Cron Worked on wed1.2.2');
        }
        return $this;
    }

}

It doesnot sends email I checked the cron.log file

[2019-06-19 11:29:46] main.ERROR: Cron Job gme_alerttest_cron has an error: No such entity with email = emailaddress@gmail.com, websiteId = 0. Statistics: {"sum":0,"count":1,"realmem":0,"emalloc":0,"realmem_start":81788928,"emalloc_start":77602808} [] [] [2019-06-19 11:29:46] main.CRITICAL: No such entity with email = emailaddress@gmail.com, websiteId = 0 {"exception":"[object] (Magento\Framework\Exception\NoSuchEntityException(code: 0): No such entity with email = emailaddress@gmail.com, websiteId = 0 at /var/www/html/magento2/vendor/magento/module-customer/Model/CustomerRegistry.php:121)"} []

Your Answer

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

Browse other questions tagged or ask your own question.