Yii2 如何处理 Swift_TransportException 异常?

Chi*_*may 5 exception-handling swiftmailer yii2 yii2-advanced-app

尝试使用 swiftmailer 发送邮件时,出现以下错误:

Expected response code 250 but got code "550", with message "550 User test@test.com has exceeded its 24-hour sending limit. Messages to 250 recipients out of 250 allowed have been sent. Relay quota will reset in 1.47 hours.
Run Code Online (Sandbox Code Playgroud)

我已将 swiftmailer 放在 try catch 块中,如下所示:

public function sendMail($emailTemplateName, $subject, $body, $fromEmail, $toEmail)
{
        try
        {
            return Yii::$app->mailer->compose(['html' => $emailTemplateName], ['emailBody' => $body])
                ->setFrom([ $fromEmail => Yii::$app->params['siteTitle'] ])
                ->setTo($toEmail)
                ->setSubject($subject)
                ->send();
        }
        catch(Swift_SwiftException $exception)
        {
            return 'Can sent mail due to the following exception'.print_r($exception);
        }
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过Swift_SwiftExceptionException但没有被抓住。

我该如何处理这个异常?

Chi*_*may 5

好的,我知道了。我需要\Swift_TransportException在捕获中使用。