I am trying to send an email to a address via cron job but there is no response I tried it using controller it sends the mail correctly.



namespace Vendor\Module\Cron;
use Magento\Framework\Mail\Template\TransportBuilder;
class Mail
    * @var \Psr\Log\LoggerInterface
    private $logger;
    * @var TransportBuilder
    private $transportBuilder;

    public function __construct(
        \Psr\Log\LoggerInterface $logger,
        TransportBuilder $transportBuilder
        $this->logger = $logger;
        $this->transportBuilder = $transportBuilder;

    * Execute the cron
    * @return void
    public function execute()
        try {
        $templateVars = [];
        $transport = $this->transportBuilder->setTemplateIdentifier('acme_dropshipment_email')
        ->setTemplateOptions( [ 'area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => 1 ] )
        ->setTemplateVars( $templateVars )
        ->setFrom( [ "name" => "rick", "email" => "[email protected]" ] )
        ->addTo('[email protected]')
        ->setReplyTo('[email protected]')
        $this->logger->info('Cron Works');
        return $this;   
        } catch (Exception $e) {



    <?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="alert_group">
        <job instance="Vendor\Module\Cron\Mail" method="execute" name="vendor_module_cron">
            <schedule>* * * * *</schedule>


    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="alert_group">


    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
    <template id="acme_dropshipment_email" label="DropShipment Email" file="dropshipment.html" type="html" module="Vendor_Module" area="frontend"/>


    Hello world :D
  • Now this code is working for you ? Now i am looking same thing. I want to send csv file direct on email. Commented Jan 17, 2022 at 11:50

2 Answers 2


This library helps to identify the issues.

Run the below commands in the Magento root directory to download the n98-magerun2.phar.

wget https://files.magerun.net/n98-magerun2.phar

Then trigger your custom cron by running below command.

php n98-magerun2.phar sys:cron:run vendor_module_cron

If your custom cron php has any error, it will throw the exceptions. Use those exception details and fixed it.

I hope it helps.


I recommend that you put your email logic into a helper and load that helper via a console command. Once you've confirmed the email is sending and using the template (and the template looks good) then load the helper via a cron process and trigger a send.

Cron and console will use same state.

IMHO a slight different approach on this makes your life easier.

But a quick scan over your code and it looks logical. No obvious errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.