I am trying to send mail from the scheduled task using MailService but in that, I need a sales channel Id how can I get that?
Can I send mail without the sales channel Id? or Is there any other method to send mail
Here is my code:
services.xml
<service id="Plugin\Service\ScheduledTask\TaskHandler">
<argument type="service" id="Shopware\Core\Content\Mail\Service\MailService"/>
<argument type="service" id="scheduled_task.repository" />
<tag name="messenger.message_handler" />
</service>
TaskHandler.php
class TaskHandler extends ScheduledTaskHandler
{
private AbstractMailService $mailService;
public function __construct(AbstractMailService $mailService,EntityRepositoryInterface $scheduleTaskRepository)
{
parent::__construct($scheduleTaskRepository);
$this->mailService = $mailService;
}
public static function getHandledMessages(): iterable
{
return [ Task::class ];
}
public function run(): void
{
$recipients = [
'test@gmail.com' => 'test'
];
$data = new DataBag();
$data->set('recipients', $recipients);
$data->set('senderName', 'RAJ');
$data->set('subject', 'test');
$data->set('contentPlain', 'test');
$data->set('salesChannelId','');//TODO
$this->mailService->send($data->all(), Context::createDefaultContext(), []);
}
}