我正在使用EWS托管Api 2.2和Exchange Server 2010_SP2。我正在开发一些东西来获取电子邮件的附件。我想知道我是否可以从任何地方获取电子邮件中任何附件的网址。
由于
答案 0 :(得分:0)
你可以,但它可能不那么漂亮。总之,您可以使用WebClientReadFormQueryString作为构建附件链接的基础。 OWA中的附件具有与父消息相同的ID。以下是我为构建链接所做的工作。
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Diagnostics;
using System.IO;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Auth;
/******************************************************/
//pass WebClientReadFormQueryString and the attachment index value
private static string makeAttachmentLinkForOWA(string queryString, int itemNum = 0)
{
//extract the id. The url encoding is lost
NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString);
//apply url encoding to the extracted id
string msgId = HttpUtility.UrlEncode(queryCollection.Get("id"));
//this is to increment attid0
char attachmentLetter = Convert.ToChar(itemNum + 65);
//build the query prefix
string a = "https://webmail.myorg.org/owa/attachment.ashx?attach=1&id=";
//build the attachment postfix. attid0 works with documents (docx, xls, etc.) but failed on .wav
string b = String.Format("&attid0=BAA{0}AAAA&attcnt=1", attachmentLetter.ToString());
//its broken if there isn't a messageId
if (msgId == null)
{
return null;
}
else
{
//build the link
string link = String.Format("{0}{1}{2}", a, msgId, b);
return link;
}
}