Tuesday, March 21, 2017

Override setGlobalTo of Laravel Mailer

I am having trouble with sending mails from Laravel to SendGrid API in my development environment.

The thing is that I have a global TO set on my mail.php config file so that the all the emails that gets sent, go to that adress.

But the setGlobalTo() function of the Mailer class actually set the same email to the TO, the CC, and the BCC.

SendGrid on his endpoint doesn't accept duplicated emails so it throws an error

It gets fixed if I comment the 2 lines that sets the CC and the BCC like:

protected function setGlobalTo($message){
    $message->to($this->to['address'], $this->to['name'], true);
    //$message->cc($this->to['address'], $this->to['name'], true);
    //$message->bcc($this->to['address'], $this->to['name'], true);
}

But it is a vendor file, so, the question is...

How can I easily override that method or unset the cc and bcc before sending my emails on a development environment?

Thank you!



via Carlos Fdev

Advertisement