sendMessage method

Future<SmtpResponse> sendMessage(
  1. MimeMessage message, {
  2. bool use8BitEncoding = false,
  3. MailAddress? from,
  4. List<MailAddress>? recipients,
})

Sends the specified message.

Set use8BitEncoding to true for sending a UTF-8 encoded message body. Specify from in case the originator is different from the From header in the message. Optionally specify the recipients, in which case the recipients defined in the message are ignored.

Implementation

Future<SmtpResponse> sendMessage(MimeMessage message,
    {bool use8BitEncoding = false,
    MailAddress? from,
    List<MailAddress>? recipients}) {
  final recipientEmails = recipients != null
      ? recipients.map((r) => r.email).toList()
      : message.recipientAddresses;
  if (recipientEmails.isEmpty) {
    throw SmtpException(this, SmtpResponse(['500 no recipients']));
  }
  return sendCommand(
    SmtpSendMailCommand(
      message,
      from,
      recipientEmails,
      use8BitEncoding: use8BitEncoding,
    ),
  );
}