0 votes

I create an EWS outlook app.

When saving an email i need to use the mail.dll to access the mail item.

is there a sample how to go about that? i only have the token from the EWS outlook app and not the user name.

how can i access a mail item using a token an a mail item id?

Thanks!

by (300 points)
Do you have a raw eml version of the message?
this is how it is done by Microsoft:

 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1)
            {
                Url = new Uri(value.outlookTokenInfo.ewsUrl),
                Credentials =  new OAuthCredentials(value.outlookTokenInfo.token)
            };

and than:

 Item item = Item.Bind(service, value.outlookTokenInfo.item);

as you can see to get an email item the authentication is done using a token and mail item id.

is there a similar way to do the same using mail.dll?

1 Answer

0 votes

Mail.dll support OAuth 2.0:

Scenario for installed applications:
https://www.limilabs.com/blog/oauth2-outlook-com-imap-installed-applications

Scenario for web applications:
https://www.limilabs.com/blog/oauth2-outlook-com-imap-web-applications

For Office365 / Exchange Online, consider reading this articles:

https://www.limilabs.com/blog/oauth2-office365-exchange-imap-pop3-smtp

https://www.limilabs.com/blog/oauth2-password-grant-office365-exchange-imap-pop3-smtp

Basically if you have an access token, the code is very simple:

string accessToken = ...;
using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap-mail.outlook.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();
}
by (297k points)
edited by
...