When you use C # To receive emails from an Exchange mailbox, you must specify the user name, password, and domain name. The other information is the email address, as shown in the following example:
// Connect to the server exchangeservice service = new exchangeservice (exchangeversion. exchange2007_sp1); service. credentials = new networkcredential ("User Name", "password", "Domain Name"); service. autodiscoverurl ("email address ");
Another way is to directly specify the WSDL address of the Exchange Server,CodeAs follows:
// Connect to the server exchangeservice service = new exchangeservice (exchangeversion. exchange2007_sp1); service. credentials = new networkcredential ("User Name", "password", "Domain Name"); service. url = new uri (http: // server/EWS/exchange. asmx );
The difference between the two methods:
The first method is to directly write the email address, which will automatically locate your server address, so that your server address will change and the code will not be modified, but the disadvantage is that the address location error is often reported or cannot be found (I don't know why)
The second method has the advantage of faster positioning and accuracy. Basically, no error is reported. The disadvantage is that if the server address changes, you still need to modify the code.
Personal conclusion: the second method is better. To avoid errors, we recommend that you read the address from the configuration file for convenient management.