+1 vote

We have a web app that we use the google api to send emails from the web app. We have a google api token and refresh token. Can we use this with the mail.dll?

by

1 Answer

0 votes
 
Best answer

I assume it is OAuth2 token. Yes you can use it with Mail.dll,
remember however that token must be issued for
GoogleScope.ImapAndSmtp.Name and GoogleScope.EmailScope.Name scopes.

GoogleApi api = new GoogleApi(accessToken);
string user = api.GetEmailPlus();

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.LoginOAUTH2(user, accessToken);

    imap.SelectInbox();
    List<long> uids = imap.Search(Flag.Unseen);

    foreach (long uid in uids)
    {
        var eml = imap.GetMessageByUID(uid);
        IMail email = new MailBuilder().CreateFromEml(eml);
        Console.WriteLine(email.Subject);
    }
    imap.Close();
}

You can find more here:
https://www.limilabs.com/mail/samples#imap-gmail-oauth2

by (297k points)
...