Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

email - Why does Laravel sending mail method not have a try catch?

I have a project in which several emails are sent in certain situations. The mail service used is sendgrid and sometimes it gives an exception, which prevents the rest of the code after sending the email from executing. Do I have to wrap every Mail::send into a try catch block?

                Mail::send('view', [
                    'variable' => $variable
                ], function ($message) use ($address, $variable) {
                    $message->to($address)
                        ->subject("Subject");
                });

I looked at Mailer.php where the send() method is defined and I saw that it calls this method

  return $this->sendSwiftMessage($message);

which looks like this

    protected function sendSwiftMessage($message)
    {
        if ($this->events) {
            $this->events->fire(new EventsMessageSending($message));
        }

        try {
            return $this->swift->send($message, $this->failedRecipients);
        } finally {
            $this->swift->getTransport()->stop();
        }
    }

Does it crash because it does not have a catch block? Why doesn't it?

question from:https://stackoverflow.com/questions/65651719/why-does-laravel-sending-mail-method-not-have-a-try-catch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...