send method
Send the email immediately
Implementation
Future<void> send() async {
try {
validate();
final content = build();
final html = content.toHtml();
final text = content.toText();
final mail = Mail().toMany(to).subject(subject).html(html).text(text);
// Add optional fields
if (cc.isNotEmpty) mail.ccMany(cc);
if (bcc.isNotEmpty) mail.bccMany(bcc);
if (from != null) {
// Note: You might need to extend Mail class for custom from
}
if (replyTo != null) {
// Note: You might need to extend Mail class for reply-to
}
// Add attachments
// for (final attachment in attachments) {
// // Add attachment logic here
// }
await mail.sendMail();
print('✅ Email sent to: ${to.join(', ')}');
} catch (e) {
print('❌ Failed to send email: $e');
rethrow;
}
}