Catch HTML message and possible error message after sending e-mail


I am using the default swift mailer and i like to store every send e-mail by the system in a database. I am using the following simple code;

$mailer = Yii::$app->mailer->compose(’@app/views/mail/test, $params);

$mailer->setFrom([Yii::$app->params[‘mail’][‘fromEmail’] => Yii::$app->params[‘mail’][‘fromName’]]);

$mailer->setFrom([‘’ => ‘System’]);

$mailer->setTo([‘’ => ‘Kevin’]);

$mailer->setSubject(‘Test mail’);

// send mail

$sent = $mailer->send();


[*]How can I catch the rendered HTML message, i found the "toString" method, but there the whole raw message will be returned, i only need the HTML code of the message ?

[*]How can I catch an possible error message when sending fails?