【问题标题】:Retrieving Some Email Information检索一些电子邮件信息
【发布时间】:2012-11-27 21:05:59
【问题描述】:

我正在尝试从发送到 Outlook 电子邮件的电子邮件中获取一些信息。我已成功连接到 Exchange Server,并且能够从带有附件的电子邮件中检索一些信息(我正在跳过不带附件的电子邮件)。

我有什么:我可以检索附件文件名、电子邮件日期和电子邮件主题。

我需要什么:我还需要检索发件人姓名和电子邮件。根据我所做的,我可以检索电子邮件的正文(HTML 格式),但不能仅检索正文(需要 Exchange 2013 - Hello MS 广告)。

我是 C# 新手,今天是我第一次连接到 Exchange Server。我从阅读中注意到,“发现”在它可以获得的内容方面是有限的,我需要绑定消息才能从电子邮件中获取更多信息。

到目前为止的代码:

foreach (Item item in findResults.Items)

                if (item.HasAttachments) // && item.Attachments[0] is FileAttachment)
                {
                    item.Load();
                    FileAttachment fileAttachment = item.Attachments[0] as FileAttachment;
                    date = Convert.ToString(item.DateTimeCreated);
                    name = Convert.ToString(fileAttachment.Name);
                    fileAttachment.Load("C:\\test\\" + fileAttachment.Name);
                    Console.WriteLine(name);
                    Console.WriteLine(item.Subject);
                    Console.WriteLine(date);
                }

我的问题是,如果我执行 EmailMessage msg = EmailMessage.Bind ... 我需要什么信息才能获取更多信息?

【问题讨论】:

    标签: c# exchange-server exchangewebservices


    【解决方案1】:

    已解决 - 用于获取发件人电子邮件和姓名以及加载附件。

    我使用了EmailMessage类(只是在上面的循环中添加了它,并在开头添加了变量):

                        EmailMessage msg = (EmailMessage)item;
                        senderemail = Convert.ToString(msg.Sender.Address);
                        sendername = Convert.ToString(msg.Sender.Name);
    

    然后我可以在控制台上重现这些:

                        Console.WriteLine(senderemail);
                        Console.WriteLine(sendername);
    

    另外,为了加载电子邮件的附件,我在开头声明了一个 byte[] 变量,加载附件,转换它,并将其内容写入控制台:

                        fileAttachment.Load();
                        filecontent = fileAttachment.Content;
                        System.Text.Encoding enc = System.Text.Encoding.ASCII;
                        string strFileContent = enc.GetString(filecontent);
                        Console.WriteLine(strFileContent);
    

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-11
      • 2021-02-06
      • 2012-01-12
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多