sendMessage method
Future<void>
sendMessage(
- MimeMessage message, {
- MailAddress? from,
- bool appendToSent = true,
- bool supportUnicode = false,
- Mailbox? sentMailbox,
- bool use8BitEncoding = false,
- List<
MailAddress> ? recipients,
Sends the specified message.
Use MessageBuilder to create new messages.
Specify from as the originator in case it differs from the From
header of the message.
Optionally set appendToSent to false in case the message should NOT
be appended to the SENT folder.
By default the message is appended. Note that some mail providers
automatically append sent messages to
the SENT folder, this is not detected by this API.
You can also specify if the message should be sent using 8 bit encoding
with use8BitEncoding, which default to false.
Optionally specify the recipients, in which case the recipients
defined in the message are ignored.
Optionally specify the sentMailbox when the mail system does not
support mailbox flags.
first
Implementation
Future<void> sendMessage(
MimeMessage message, {
MailAddress? from,
bool appendToSent = true,
bool supportUnicode = false,
Mailbox? sentMailbox,
bool use8BitEncoding = false,
List<MailAddress>? recipients,
}) async {
await _prepareConnect();
final futures = <Future>[
_outgoingLock.synchronized(
() => _sendMessageViaOutgoing(
message,
from,
use8BitEncoding,
recipients,
supportUnicode: supportUnicode,
),
),
];
if (appendToSent && _incomingMailClient.supportsAppendingMessages) {
sentMailbox ??= getMailbox(MailboxFlag.sent);
if (sentMailbox == null) {
_incomingMailClient
.log('Error: unable to append sent message: no no mailbox with '
'flag sent found in $mailboxes');
} else {
futures.add(
appendMessage(
message,
sentMailbox,
flags: [MessageFlags.seen],
),
);
}
}
await Future.wait(futures);
}