authenticate method
Future<void>
authenticate(
- ServerConfig serverConfig, {
- ImapClient? imap,
- PopClient? pop,
- SmtpClient? smtp,
override
Authenticates with the specified mail service
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.toValueOrThrow('no [ImapClient] found').login(name, pwd);
break;
case ServerType.pop:
await pop.toValueOrThrow('no [PopClient] found').login(name, pwd);
break;
case ServerType.smtp:
if (smtp == null) {
throw ArgumentError('no [SmtpClient] found');
}
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 InvalidArgumentException(
'Unknown server type ${serverConfig.typeName}',
);
}
}