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 userName = this.userName;
final accessToken = token.accessToken;
switch (serverConfig.type) {
case ServerType.imap:
await imap
.toValueOrThrow('no [ImapClient] found')
.authenticateWithOAuth2(userName, accessToken);
break;
case ServerType.pop:
await pop
.toValueOrThrow('no [PopClient] found')
.login(userName, accessToken);
break;
case ServerType.smtp:
await smtp
.toValueOrThrow('no [SmtpClient] found')
.authenticate(userName, accessToken, AuthMechanism.xoauth2);
break;
default:
throw InvalidArgumentException(
'Unknown server type ${serverConfig.typeName}',
);
}
}