使用EWS获取原始电子邮件文本(标题,正文和编码附件)

时间:2013-10-10 22:52:53

标签: exchangewebservices

有没有办法使用EWS获取原始电子邮件文本? 我想获得整个文本,包括标题,正文和编码附件。

这可能吗?

1 个答案:

答案 0 :(得分:3)

我不知道这是不是你要找的,但它应该有帮助。

下载整个邮件文件,包括编码附件,标题,主题,发件人,收件人等......

试试这个:     

static void Main(string[] args)
{
    try
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
        service.Credentials = new NetworkCredential("USR", "PWD", "Domain");
        service.AutodiscoverUrl("someone@example.com");

        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(int.MaxValue));

        Console.WriteLine("Found : " + findResults.TotalCount + " messages");

        foreach (EmailMessage message in findResults.Items)
        {
            try
            {
                message.Load(new PropertySet(ItemSchema.MimeContent));
                MimeContent mc = message.MimeContent;
                // I use this format to rename messages files, you can do whatever you want
                string n = string.Format("-{0:yyyy-MM-dd_HH-mm-ss-ffff}.eml", DateTime.Now);
                string path = @"C:\folder\message" + n;
                FileStream fs = new FileStream(path, FileMode.Create);
                fs.Write(mc.Content, 0, mc.Content.Length);
                fs.Flush();
                fs.Close();

                //message.Delete(DeleteMode.HardDelete);   // It deletes the messages permanently
                //message.Delete(DeleteMode.MoveToDeletedItems);  // It moves the processed messages to "Deleted Items" folder

            }
            catch (Exception exp)
            {
                Console.WriteLine("Error : " + exp);
            }
        }
    }
    catch (Exception exp2)
    {
        Console.WriteLine("Error : " + exp2);
    }
}

希望它有所帮助,干杯。