Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendGrid category not being set

I'm redoing a project that has SendGrid integrated for mailing.

Well, I'm using Laravel and Mailable classes, and I have created a function to set the SendGrid category:

public function setSendgridCategory($category){
    $encodedCategory = json_encode(['category' => $category]);
    $this->withSwiftMessage(function (\Swift_Message $message) use ($encodedCategory){
        $message->getHeaders()->addTextHeader('X-SMTPAPI', $encodedCategory);
    });
}

I have a listener which logs my headers, and they look like:

Date: Wed, 18 Jan 2017 13:47:32 +0100
Subject: XXXXXXXXX.
From: xXXXXXx <[email protected]>
To: XXXXxxx <[email protected]>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SMTPAPI: {"category":"Otros"}

Also tried with an array

X-SMTPAPI: {"category":["Otros"]}

The name of the category is exactly the same as the one that is already being tracked on SendGrid, but when I look on the SendGrid activity log, the email is sent, but no category is set.

Any ideas?

like image 342
Carlos Fdev Avatar asked Jun 04 '26 21:06

Carlos Fdev


2 Answers

Category needs to be an array. Try: {"category":["Otros"]}

like image 104
bwest Avatar answered Jun 06 '26 10:06

bwest


Well, after testing everything that came to my mind, and messing with the encodings as @bwest suggested, changing the driver on my .env file solved it.

I don't know where did I get it from, but I had my driver set as

MAIL_DRIVER=sendgrid

and it was sending mails correctly, so I didn't pay attention to it, I changed it to

MAIL_DRIVER=smtp

and now my categories are set correctly.

like image 38
Carlos Fdev Avatar answered Jun 06 '26 10:06

Carlos Fdev