繁体   English   中英

检索一些电子邮件信息

[英]Retrieving Some Email Information

我正在尝试从发送到 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 ... 我需要什么信息才能获取更多信息?

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

我使用了 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM