sherlock1982 / ews-managed-api

https://www.nuget.org/packages/Microsoft.Exchange.WebServices.NETStandard/
Other
102 stars 46 forks source link

Authentication problem #43

Closed Dean-ZhenYao-Wang closed 2 years ago

Dean-ZhenYao-Wang commented 5 years ago

This is my code //ExchangeVersion.Exchange2007_SP1 为要对应Exchange的版本 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2016); // 用户名 密码 service.Credentials = new WebCredentials(@"suz_packinglist", "Tfme@12345"); service.UseDefaultCredentials = true; service.TraceFlags = TraceFlags.All; service.TraceEnabled = true; //自动发现服务查找您的 EWS 终结点。,并赋值给ExchangeService对象的URL属性 service.AutodiscoverUrl("suz_packinglist@tf-amd.com", RedirectionUrlValidationCallback); Console.WriteLine("========service.Url======="); Console.WriteLine(service.Url); EmailMessage email = new EmailMessage(service); //收件人 email.ToRecipients.Add("zhenyao_wang@wd3e.com"); //标题 email.Subject = "HelloWorld"; //正文 email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API"); //发送邮件 email.Send();

Console.WriteLine(service.Url); The execution result is"" zhenyao_wang@wd3e.com did not receive the sent email

Dean-ZhenYao-Wang commented 5 years ago

This is what the console prints

<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:53Z">
Starting SCP lookup for domainName='tf-amd.com', root path=''
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:54Z">
LDAP call failed, exception: System.Runtime.InteropServices.COMException (0x8007054B): 指定的域不存在,或无法联系。
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetScpUrlList(String domainName, String ldapPath, Int32&amp; maxHops)
   at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetAutodiscoverScpUrlsForDomain(String domainName)
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:54Z">
Determining which endpoints are enabled for host tf-amd.com
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:55Z">
I/O error: One or more errors occurred. (请求的名称有效,但是找不到请求的类型的数据。)
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:55Z">
No Autodiscover endpoints are available for host tf-amd.com
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:55Z">
Determining which endpoints are enabled for host autodiscover.tf-amd.com
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2019-10-18 06:27:55Z">
Host returned enabled endpoint flags: Legacy, Soap, WsSecurity, OAuth
</Trace>
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="AutodiscoverRequest" Tid="1" Time="2019-10-18 06:27:55Z" Version="15.0.913.15">
  <soap:Envelope xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <a:RequestedServerVersion>Exchange2016</a:RequestedServerVersion>
      <wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
      <wsa:To>https://autodiscover.tf-amd.com/autodiscover/autodiscover.svc</wsa:To>
    </soap:Header>
    <soap:Body>
      <a:GetUserSettingsRequestMessage xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover">
        <a:Request>
          <a:Users>
            <a:User>
              <a:Mailbox>suz_packinglist@tf-amd.com</a:Mailbox>
            </a:User>
          </a:Users>
          <a:RequestedSettings>
            <a:Setting>InternalEwsUrl</a:Setting>
            <a:Setting>ExternalEwsUrl</a:Setting>
          </a:RequestedSettings>
        </a:Request>
      </a:GetUserSettingsRequestMessage>
    </soap:Body>
  </soap:Envelope>
</Trace>
========service.Url=======

读取开始
读取结束