gpt4 book ai didi

java - 无法使用 EWS Java API 发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 05:04:45 27 4
gpt4 key购买 nike

我使用 EWS 在 Exchange 2010 上发送电子邮件,如下所示:

ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials(email, password);
service.setCredentials(credentials);
service.setUrl(new java.net.URI("https://" + host
+ "/EWS/Exchange.asmx"));
service.setTraceEnabled(true);

EmailMessage msg = new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Managed API."));
msg.getToRecipients().add("email");
msg.send();

邮件未发送至收件箱,我不知道问题所在。启用跟踪后,我得到以下信息:

<Trace Tag="EwsRequestHttpHeaders" Tid="1" Time="2012-10-14 11:13:46Z">
POST /EWS/Exchange.asmx HTTP/1.1
Content-type : text/xml; charset=utf-8
Accept-Encoding : gzip,deflate
Keep-Alive : 300
User-Agent : ExchangeServicesClient/0.0.0.0
Connection : Keep-Alive
Accept : text/xml
</Trace>

<Trace Tag="EwsRequest" Tid="1" Time="2012-10-14 11:13:47Z">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header><t:RequestServerVersion Version="Exchange2010_SP1"></t:RequestServerVersion></soap:Header>
<soap:Body><m:CreateItem MessageDisposition="SendOnly"><m:Items><t:Message><t:Subject>Hello world!</t:Subject><t:Body BodyType="HTML">Sent using the EWS Managed API.</t:Body><t:ToRecipients><t:Mailbox><t:EmailAddress>adamb@fabrikam.com</t:EmailAddress></t:Mailbox></t:ToRecipients></t:Message></m:Items></m:CreateItem></soap:Body>
</soap:Envelope>
</Trace>

14/10/2012 01:13:48 م org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: NTLM authentication scheme selected
<Trace Tag="EwsResponseHttpHeaders" Tid="1" Time="2012-10-14 11:13:48Z">
200 text/xml; charset=utf-8
X-AspNet-Version : 2.0.50727
X-EwsPerformanceData : RpcC=3;RpcL=15;LdapC=0;LdapL=0;
Persistent-Auth : true
Date : Sun, 14 Oct 2012 11:13:48 GMT
Vary : Accept-Encoding
Transfer-Encoding : chunked
Content-Encoding : gzip
Content-Type : text/xml; charset=utf-8
X-Powered-By : ASP.NET
Server : Microsoft-IIS/7.5
Cache-Control : private
</Trace>

<Trace Tag="EwsResponse" Tid="1" Time="2012-10-14 11:13:48Z">
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header><h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="218" MinorBuildNumber="14" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/></s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:CreateItemResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:Items/></m:CreateItemResponseMessage></m:ResponseMessages></m:CreateItemResponse></s:Body>
</s:Envelope>
</Trace>

请告知如何解决此问题。

最佳答案

交换服务器响应一切正常:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="218" MinorBuildNumber="14" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:CreateItemResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:Items/>
</m:CreateItemResponseMessage>
</m:ResponseMessages>
</m:CreateItemResponse>
</s:Body>
</s:Envelope>

您应该检查 Exchange 端,或者询问您的 Exchange 服务器管理员发生了什么情况(例如,某些垃圾邮件过滤或其他内容),因为从代码角度和 SOAP 请求/响应的角度来看,没有任何问题。

关于java - 无法使用 EWS Java API 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12881753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com