Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4626470
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:25:31+00:00 2026-05-22T03:25:31+00:00

Summary: I need to login to my mailbox using EWS and but i keep

  • 0

Summary:
I need to login to my mailbox using EWS and but i keep getting 440/401 error.

question:
Anything obvious in my code as to why I keep getting either 401 or 440 errors?

Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Autodiscover;


namespace MailboxListenerEWS
{
    class Program
    {
        //Authentication to exchange 2007 with webdav and filebasedauth (FBA) in C#
        //can hardcode a username to connect a mailbox with
        internal static string dUser = "username";//username to log into email account
        internal static string dDomain = "domain";//domain of username used
        internal static string dPassword = "Password";//password of username used
        internal static string MailBoxAliasName = "mailboxname";//mailbox to authenticate too
        internal static string ExchangeServerName = "exchangeName"; //not always needed
        internal static string ReadAttachments = "0"; //1 means read attachments, 0 means dont
        internal static string MailBoxEarliestDateToRead = "2011-01-05T00:00:00.000Z";//date of emails to read from



        static void Main(string[] args)
        {
            //Connect to server
            //ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            //service.Credentials = new NetworkCredential("name", "pwd", "domain");
            service.Credentials = new NetworkCredential("dUser", "dPassword", "dDomain");

            //log in to mailbox
            try
            {
                //service.Url = new Uri(serviceurl);
                //Console.WriteLine(serviceurl);
                //service.AutodiscoverUrl(MailBoxAliasName);
                service.Url = new Uri("https://" + ExchangeServerName + "/EWS/" + MailBoxAliasName + "/inbox");
            }
            catch (AutodiscoverRemoteException ex)
            {
                Console.WriteLine("Exception thrown: " + ex.Error.Message);
                Console.ReadLine();
            }


            //List folders
            try
            {
                //Listing all the subfolders of the Inbox
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(int.MaxValue));
                foreach (Item item in findResults)
                {
                    Console.WriteLine(item.Subject);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception thrown: " + ex.Message);
                Console.ReadLine();
            }


        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:25:32+00:00Added an answer on May 22, 2026 at 3:25 am

    Are you sure your server uses 2007 SP1? Also, if you’re not sure of the correct URL, try using the AutoDiscover, where “user@domain.com” is an actual email address on your domain.

    service.AutodiscoverUrl("user@domain.com");
    

    Also, you’re setting your URL equal to a URi . I don’t think that’s legal; is it even compiling?

    Here is some sample code that I used as a starting point when I implemented something similar – codeproject.com

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Executive summary: I need a way to determine whether a Windows process I've spawned
(Summary: My users need to be able to edit the structure of their dynamically
Summary: 1. Need to open a new window to display a survey from a
Summary: I am having trouble connecting to an exchange 2007 mailbox that is running
I'm using successfully GIN on my GWT projet. Now my RPC service will need
I am using Authlogic to do some simple signup and login stuff. In my
Probably this is often problem, but I can't solve it. I need to automaticallly
I need to wrap the Validation Summary in a div . How do I
for a data frame as follow id<-c(1,1,2,3,3,2) p<-c(10,0,22,34,0,0) df<-data.frame(id,p) I need a summary table
I need to change the following Bash code to Zsh TODO_OPTIONS=--timeout --summary cd ()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.