authenticate method
Future<void>
authenticate(
- ServerConfig serverConfig, {
- ImapClient? imap,
- PopClient? pop,
- SmtpClient? smtp,
override
Implementation
@override
Future<void> authenticate(ServerConfig serverConfig,
{ImapClient? imap, PopClient? pop, SmtpClient? smtp}) async {
final name = userName!;
final pwd = password!;
switch (serverConfig.type) {
case ServerType.imap:
await imap!.login(name, pwd);
break;
case ServerType.pop:
await pop!.login(name, pwd);
break;
case ServerType.smtp:
final authMechanism = smtp!.serverInfo.supportsAuth(AuthMechanism.plain)
? AuthMechanism.plain
: smtp.serverInfo.supportsAuth(AuthMechanism.login)
? AuthMechanism.login
: AuthMechanism.cramMd5;
await smtp.authenticate(name, pwd, authMechanism);
break;
default:
throw StateError('Unknown server type ${serverConfig.typeName}');
}
}