MailClient constructor
MailClient(
- MailAccount account, {
- bool isLogEnabled = false,
- int? downloadSizeLimit,
- EventBus? eventBus,
- String? logName,
- bool onBadCertificate()?,
Creates a new highlevel online mail client for the given account
.
Specify the account settings with account
.
Set isLogEnabled
to true to debug connection issues.
Specify the optional downloadSizeLimit
in bytes to only download messages automatically that are this size or lower.
onBadCertificate
is an optional handler for unverifiable certificates. The handler receives the X509Certificate, and can inspect it and decide (or let the user decide) whether to accept the connection or not. The handler should return true to continue the SecureSocket connection.
Implementation
MailClient(
MailAccount account, {
bool isLogEnabled = false,
int? downloadSizeLimit,
EventBus? eventBus,
String? logName,
bool Function(X509Certificate)? onBadCertificate,
}) : _eventBus = eventBus ?? EventBus(),
_account = account,
_isLogEnabled = isLogEnabled,
_downloadSizeLimit = downloadSizeLimit {
final config = _account.incoming!;
if (config.serverConfig!.type == ServerType.imap) {
_incomingMailClient = _IncomingImapClient(
_downloadSizeLimit, _eventBus, _isLogEnabled, logName, config, this,
onBadCertificate: onBadCertificate);
} else if (config.serverConfig!.type == ServerType.pop) {
_incomingMailClient = _IncomingPopClient(
_downloadSizeLimit, _eventBus, _isLogEnabled, logName, config, this,
onBadCertificate: onBadCertificate);
} else {
throw StateError(
'Unsupported incoming server type [${config.serverConfig!.typeName}].');
}
final outgoingConfig = _account.outgoing!;
if (outgoingConfig.serverConfig!.type != ServerType.smtp) {
print(
'Warning: unknown outgoing server type ${outgoingConfig.serverConfig!.typeName}.');
}
_outgoingMailClient = _OutgoingSmtpClient(
this,
_account.outgoingClientDomain,
_eventBus,
_isLogEnabled,
'SMTP-$logName',
outgoingConfig,
onBadCertificate: onBadCertificate,
);
}