I am using Symfony Custom Transport, and when I send mail with MailerInterface, as a result I am getting its own messageId. However, I want to get the messageId of the provider, that I use in my Custom Transport(In my case it is Brevo). Also I
This is some code from my emailtransport.php
namespace Ngo\Project\NotifierBundle\Business\Engine\Transport\Email;
protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface {
$payLoad = $this->getPayload($email, $envelope);
if(!empty($payLoad['campaignId'])) {
$response = $this->client->request('POST', "https://api.brevo.com/v3/emailCampaigns/{$payLoad['campaignId']}/sendNow", [
'headers' => [
'accept' => 'application/json',
'api-key' => $_ENV["EMAIL_API_KEY"],
],
]);
}
else{
$body = json_encode($payLoad);
$response = $this->client->request('POST', 'https://api.brevo.com/v3/smtp/email', [
'body' => $body,
'headers' => [
'accept' => 'application/json',
'api-key' => $_ENV['EMAIL_API_KEY'],
'content-type' => 'application/json',
],
]);
}
return $response;
}
Also I have created my own service, in which I use send method of MailerInterface.
<?php
namespace Ngo\Project\NotifierBundle\Business\Engine;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\RawMessage;
class Emailer implements MailerInterface
{
private TransportInterface $transport;
private string $messageId;
public function __construct(TransportInterface $transport)
{
$this->transport = $transport;
}
public function send(RawMessage $message, Envelope $envelope = null): void
{
$this->messageId = $this->transport->send($message)->getMessageId();
}
/**
* @return string
*/
public function getMessageId(): string
{
return $this->messageId;
}
}