簡體   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