Magento 2 import email address to Newsletter from csv

Magento 2 import email address to Newsletter from csv.

I have a requirement to import email is from CSV and import the email ids to Newsletter Subscriber list from csv.

Write a PHP script which will import Newsletter subscriber from CSV.

In this script, first i have read the email ids  from Csv , Then  first  check an email is exits  as customer

Using Magento\Customer\Api\AccountManagementInterface ‘s   function isEmailAvailable($emailId,$websiteId) and depends  on customer types Guest ( mean guest Not register) and register, i have added  the email  to  subscriber list.

For add an email to the subscriber list, we need to call factory class Magento\Newsletter\Model\SubscriberFactory  and need to Customer.Guest customer  use

$_subscriberFactory->create()->subscribe($Email);

 

and register customer ,use

$_subscriberFactory->create()->subscribeCustomerById($CustomerId);

Step1: First create importnewsletter.php at magento2 dir for import email to Newsletter subscriber list from CSV.

add below code  for

 

Step2: Create Csv file for import address.

CSV  like subscribers

Using this script,  you can Programmatically import email address to Newsletter from csv.

One thought on “Magento 2 import email address to Newsletter from csv

  • Hi Amit,
    Import newsletter works.
    How should I avoid from sending email to subscribers because my requirement is only to get emails subscribed but should not trigger any email to subscribers?

Leave a Reply

Your email address will not be published. Required fields are marked *