Outlook (401) Unauthorized when trying to access via C# RRS feed

  • Question

  • Hi, I'm getting this error when I'm trying to connect via C# to my corporate O365 account:

    //{"The request failed. The remote server returned an error: (401) Unauthorized."}

    I'd like to know if I need to get in contact with our O365 admin to get an authorization since I need to access my inbox via code. If you want to see the code.

    ExchangeService _service;
    	Console.WriteLine("Registering Exchange connection");
    	_service = new ExchangeService
    		Credentials = new WebCredentials("email", "password", "domain")
    	Console.WriteLine("new ExchangeService failed. Press enter to exit:");
    // This is the office365 webservice URL
    _service.Url = new Uri("url");
    // Prepare seperate class for writing email to the database
    	//Write2DB db = new Write2DB();
    	Console.WriteLine("Reading mail");
    	// Read 100 mails
    	foreach (EmailMessage email in _service.FindItems(WellKnownFolderName.Inbox, new ItemView(100)))
    catch (Exception e)
    	Console.WriteLine("An error has occured. \n:" + e.Message);

    I want to be crystal clear, I want to know if I need to get an authorization from our O365 Admin.


    Federico Navarrete

    • Edited by FANMixco Wednesday, September 25, 2019 10:46 AM
    Wednesday, September 25, 2019 10:08 AM

All replies