当我试图通过 EWS 发送带有内嵌图像(附件)的 HTML 消息时,这个问题就暴露出来了。然而,我已经退回到最简单的形式,发现我什至无法发送 HTML 消息。
我正在使用 C#、.NET 4、EWS API 1.1、Exchange Server 2010 SP1。
这是我的代码的核心:
ExchangeConnection = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ExchangeConnection.Credentials = new WebCredentials(Username, Password, Domain);
ExchangeConnection.Url = new Uri(ServiceURI);
string MailBody = @"<html><head></head><body>
This is a <b>test</b> <strong>HTML</strong> <em>message</em>.<br><br>
Did it work?</body></html>";
NewMessage = new EmailMessage(ExchangeConnection);
NewMessage.Subject = "Test HTML Message #001";
NewMessage.Body = MailBody;
NewMessage.Body.BodyType = BodyType.HTML;
NewMessage.ToRecipients.Add("tony@zierniemann.com");
NewMessage.Send();
使用该代码,我收到一条包含以下内容的消息:
Subject: Test HTML Message #001
Thread-Topic: Test HTML Message #001
Thread-Index: Acuy3U6nqQTa4W4ZQu6ueHPb2nPDPg==
Date: Thu, 13 Jan 2011 04:49:48 +0000
Message-ID: <2FDB41070D0AC24DB5BC8B80751063630B74A5@xxxxx.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-originating-ip: [x.x.x.x]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Spam: [F=0.2000000000; CM=0.500; S=0.200(2010122901)]
X-MAIL-FROM: <planit@xxxxx.com>
X-SOURCE-IP: [67.136.148.58]
X-AnalysisOut: [v=1.0 c=1 a=WYc53Y7r_f4A:10 a=BLceEmwcHowA:10 a=kj9zAlcOel]
X-AnalysisOut: [0A:10 a=xqWC_Br6kY4A:10 a=ERe/uVw5acJt2lgRGY+7Og==:17 a=10]
X-AnalysisOut: [TGqZ3wK2PL4t1FdnoA:9 a=mfhh-WWaJa5gWHOyyF854Vzt7EAA:4 a=Cj]
X-AnalysisOut: [uIK1q_8ugA:10]
This is a test HTML message.
Did it work?
没有 MIME 声明,也没有 text/html 部分。
如果我通过 Outlook(在同一 Exchange 服务器上)发送类似的消息,我会得到如下信息:
Subject: Test From Outlook
Thread-Topic: Test From Outlook
Thread-Index: AcuzMwJCFB8PS6wYQeeV4IeSkT/mxQ==
Date: Thu, 13 Jan 2011 15:03:17 +0000
Message-ID: <E026BAD23A27DB42B74F0DB569E9986977F237@CHALLENGER.DenverZoo.lan>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-originating-ip: [x.x.x.x]
Content-Type: multipart/alternative;
boundary="_000_E026BAD23A27DB42B74F0DB569E9986977F237CHALLENGERDenverZ_"
MIME-Version: 1.0
X-Spam: [F=0.2000000000; CM=0.500; S=0.200(2010122901)]
X-MAIL-FROM: <tonyn@xxxx.com>
X-SOURCE-IP: [67.136.148.58]
X-AnalysisOut: [v=1.0 c=1 a=olvCdMnC_oMA:10 a=BLceEmwcHowA:10 a=xqWC_Br6kY]
X-AnalysisOut: [4A:10 a=ERe/uVw5acJt2lgRGY+7Og==:17 a=2iPVs5MlqxP_VJ4oz58A]
X-AnalysisOut: [:9 a=x0_hJeNGqEWpZ67nkUaF-VHO8CMA:4 a=CjuIK1q_8ugA:10 a=yM]
X-AnalysisOut: [hMjlubAAAA:8 a=SSmOFEACAAAA:8 a=bSa8Y9cTgW9e4uXm0lgA:9 a=w]
X-AnalysisOut: [EVqP49dmlVP1afgSrUA:7 a=MTMROL1LpFqQeTH2_C9armvf4mgA:4]
--_000_E026BAD23A27DB42B74F0DB569E9986977F237CHALLENGERDenverZ_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
This is an HTML message.
What do the headers look like?
Tony
--_000_E026BAD23A27DB42B74F0DB569E9986977F237CHALLENGERDenverZ_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
... the correct html code for the message follows here ...
谁能向我解释如何使用 EWS 通过代码获取第二条消息?谢谢!