How to create newsletter subscriber programmatically magento2

To do that you can inject Magento\Newsletter\Model\SubscriberFactory in your constructor:

protected $subscriberFactory;

public function __construct(
    //
    \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
) {
    $this->subscriberFactory= $subscriberFactory;
    //
}

Then in your code you can call:

$this->subscriberFactory->create()->subscribe($email);

$email = '[email protected]';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$subscriber= $objectManager->create('Magento\Newsletter\Model\SubscriberFactory'); 
$subscriber->create()->subscribe($email);