PersistentConnection constructor
PersistentConnection(
- SmtpServer smtpServer, {
- Duration? timeout,
Implementation
PersistentConnection(SmtpServer smtpServer, {Duration? timeout}) {
_mailSendTasks.listen((_MailSendTask task) async {
_logger.finer('New mail sending task. ${task.message?.subject}');
try {
if (task.message == null) {
// Close connection.
if (_connection != null) {
await client.close(_connection);
}
task.completer.complete(null);
return;
}
_connection ??= await client.connect(smtpServer, timeout);
var report = await _send(task.message!, _connection!, timeout);
task.completer.complete(report);
} catch (e) {
_logger.fine('Completing with error: $e');
task.completer.completeError(e);
}
});
}