4

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

这可能吗?

4

1 回答 1

4

我不知道这是否是您正在寻找的,但它应该有所帮助。

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

尝试这个:

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);
    }
}

希望有帮助,加油。

于 2013-10-15T22:10:12.763 回答