private void AuthenticateImapGoogleOAuth2(Imap4Client imap)
        {
            var auth = new GoogleOAuth2Authorization();
            var granted_access = auth.RequestAccessToken(Account.RefreshToken);
            if (granted_access == null) return;
            _log.Info("IMAP SSL connecting to {0}", Account.EMail);
            imap.ConnectSsl(Account.Server, Account.Port);

            _log.Info("IMAP connecting OK {0}", Account.EMail);

            _log.Info("IMAP logging to {0} via OAuth 2.0", Account.EMail);
            imap.LoginOAuth2(Account.Account, granted_access.AccessToken);
            _log.Info("IMAP logged to {0} via OAuth 2.0", Account.EMail);
        }
        private void AuthenticateImapGoogleOAuth2(Imap4Client imap)
        {
            var auth = new GoogleOAuth2Authorization(_log);
            var granted_access = auth.RequestAccessToken(Account.RefreshToken);
            if (granted_access == null) 
                throw new DotNetOpenAuth.Messaging.ProtocolException("Access denied");
            _log.Info("IMAP SSL connecting to {0}", Account.EMail);
            imap.ConnectSsl(Account.Server, Account.Port);

            _log.Info("IMAP connecting OK {0}", Account.EMail);

            _log.Info("IMAP logging to {0} via OAuth 2.0", Account.EMail);
            imap.LoginOAuth2(Account.Account, granted_access.AccessToken);
            _log.Info("IMAP logged to {0} via OAuth 2.0", Account.EMail);
        }
Пример #3
0
        private string GetAccessToken(MailBox mail_box)
        {
            var service_type = (AuthorizationServiceType)mail_box.ServiceType;

            switch (service_type)
            {
                case AuthorizationServiceType.Google:
                    var granted_access = new GoogleOAuth2Authorization()
                        .RequestAccessToken(mail_box.RefreshToken);

                    if (granted_access != null)
                        return granted_access.AccessToken;
                    break;
            }

            return "";
        }
        public static void TestGoogleSmtpLoginViaOAuth2(string account, string refresh_token)
        {
            var authorizatior = new GoogleOAuth2Authorization();

            var granted_access = authorizatior.RequestAccessToken(refresh_token);

            if (granted_access == null) return;
            var smtp = MailClientBuilder.Smtp();
            smtp.ConnectSsl("smtp.googlemail.com", 465);
            smtp.Authenticate(account, granted_access.AccessToken, SaslMechanism.OAuth2);
            //Do some work...
            smtp.Disconnect();
        }
        public static void TestGoogleImapLoginViaOAuth2(string account, string refresh_token)
        {
            var authorizatior = new GoogleOAuth2Authorization();

            var granted_access = authorizatior.RequestAccessToken(refresh_token);

            if (granted_access == null) return;
            var imap = MailClientBuilder.Imap();
            imap.ConnectSsl("imap.googlemail.com", 993);
            imap.LoginOAuth2(account, granted_access.AccessToken);
            //Do some work...
            imap.Disconnect();
        }