sendMail method
Implementation
Future<void> sendMail() async {
_ensureConfigured();
if (_server == null) {
throw Exception('Mail not configured. Call Mail.setup() first.');
}
try {
final msg = _buildMessage();
await send(msg, _server!);
Log.debug('Mail sent to: ${_to.join(', ')}');
} on MailerException catch (e) {
final recovered = await _retryAfterReconfigure();
if (recovered) return;
Log.debug('MailerException: $e');
if (e.problems.isNotEmpty) {
for (final problem in e.problems) {
Log.debug(' - ${problem.code}: ${problem.msg}');
}
}
rethrow;
} on SocketException catch (e) {
final recovered = await _retryAfterReconfigure();
if (recovered) return;
Log.debug('SocketException while sending mail: $e');
rethrow;
} catch (e) {
Log.debug('Failed to send mail: $e');
rethrow;
}
}