How to send new password from Magento CSV import of Customers

How to send new password from Magento CSV import of Customers

September 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to send new password from Magento CSV import of Customers

Sending New Password via Magento Customer CSV Import

The Magento import process for customers is a powerful feature that allows you to bulk add or update customer accounts. However, sending out new account details including randomly generated passwords during the import process can be challenging due to the way Magento handles customer data.

The Current Approach and Its Limitations

Currently, your approach is almost correct but falls short in two key areas:

  1. Password Generation: The generatePassword(8) method assumes you are working with a pre-existing customer object. It doesn’t actually generate a new password for each new customer being created during the import.

  2. Email Sending: Magento’s email sending functionality is highly dependent on the current execution context. When called inside the _saveCustomerEntity() function, it might fail due to timing issues or missing necessary parameters.

To successfully send out new account details including randomly generated passwords during a customer import, you need to follow these steps:

  1. Create the Customer and Set the Password: Instead of trying to generate a password through generatePassword(), use Magento’s built-in getRandomString() function to create an 8-character random string for each new customer.

  2. Save the Customer Immediately: After setting the customer data, ensure you call $cust->save(); immediately to save the customer and trigger the sendNewAccountEmail() method.

  3. Handle Email Sending Errors: Wrap your email sending code inside a try-catch block to handle any failures gracefully without halting the entire import process.

Here’s the corrected code snippet:

protected function _saveCustomerEntity(array $entityRowsIn, array $entityRowsUp)
{
    if ($entityRowsIn) {
        // Insert new customers into the database
        $this->connection->insertMultiple($this->_entityTable, $entityRowsIn);

        // Begin: Send New Account Email
        foreach($entityRowsIn as $idx => $u){
            $cust = Mage::getModel('customer/customer');
            $cust->setWebsiteId(Mage::app()->getWebsite()->getId());
            $cust->loadByEmail($u['email']);

            // Check if the customer is new
            if (!$cust->getId()) {
                $password = Mage::helper('core')->getRandomString(8);
                $cust->setConfirmation(NULL);
                $cust->setPassword($password);

                try {
                    $cust->save();
                    if ($passwordChanged = $this->_passwordChanged) {
                        $this->_log("Password changed for customer with ID {$cust->getId()}");
                    }
                    $cust->sendNewAccountEmail();
                } catch (Exception $e) {
                    // Handle email sending failure
                    Mage::log($e->getMessage(), Zend_Log::ERR);
                }
            }
        }
    }

    if ($entityRowsUp) {
        // Update existing customers
        $this->connection->insertOnDuplicate(
            $this->_entityTable,
            $entityRowsUp,
            array('group_id', 'store_id', 'updated_at', 'created_at')
        );
    }
}

Conclusion

Sending new account details including passwords during a Magento customer CSV import requires careful handling of the data and the execution context. By following this corrected approach, you should now be able to successfully send out new account emails with randomly generated passwords for each newly imported customer.

Remember to clear your cache after making these changes, as Magento’s email sending configuration is cached.

For more advanced guides on Magento customizations, consider exploring our Magento Development Resources.

Configuration Email Customers Import/Export

Our network