kaisellgren / mailer

Compose and send emails from Dart. Supports file attachments, HTML emails and multiple transport methods.
MIT License
166 stars 86 forks source link

How to check if this sending is successful? #222

Closed SittiphanSittisak closed 1 year ago

SittiphanSittisak commented 1 year ago

I don't see any method like SendReport.isSuccess. How do I check this result whether this mail was sent?

final SendReport sendReport = await send(message, smtpServer);

Or when this sending failed. This function will throw an error and I can check it by using a try/catch like this.

try {
        final SendReport sendReport = await send(message, smtpServer);
        return true;
      }catch(e){
        return false;
      }
close2 commented 1 year ago

You will only get a SendReport if the message was sent successfully.

  try {
    final sendReport = await send(message, smtpServer);
    print('Message sent: ' + sendReport.toString());
  } on MailerException catch (e) {
    print('Message not sent.');
    for (var p in e.problems) {
      print('Problem: ${p.code}: ${p.msg}');
    }
  }