【问题标题】:How can ASP.Net count the number of unread emails in your inbox on Exchange 2013?ASP.Net 如何计算 Exchange 2013 收件箱中未读电子邮件的数量?
【发布时间】:2014-01-30 07:33:01
【问题描述】:

我正在尝试制作一个 ASP.Net 网站,该网站将趋势和图表化每日发送到某个电子邮件地址的电子邮件总数。我不需要下载或处理邮件,只需在收件箱中返回每天的电子邮件总数。

我看到的所有编程问题都是针对 WinForms 并使用 Outlook 来计算本地 PST 文件,而在 ASP.Net 上使用 Exchange 的情况并不多。

我找到了 EWS XML 元素 > UnreadCount,但很难使用该元素。 http://msdn.microsoft.com/en-us/library/office/aa580965(v=exchg.150).aspx

我开始使用的程序代码是为了在桌面上工作,但是我不想把它作为桌面服务留下来浪费资源并放弃这个挑战。

' Create Application class and get namespace
Dim outlook As Outlook.Application = New Outlook.ApplicationClass()
Dim ns As Outlook.NameSpace = outlook.GetNamespace("Mapi")

Dim _missing As Object = Type.Missing
ns.Logon(_missing, _missing, False, True)

' Get Inbox information in objec of type MAPIFolder
Dim inbox As Outlook.MAPIFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

' Unread emails
Dim unread As Integer = inbox.UnReadItemCount

' Display the subject of emails in the Inbox folder
For Each mail As Outlook.MailItem In inbox.Items
    Console.WriteLine(Wmail.Subject)
Next mail

【问题讨论】:

  • 您使用标志,当您阅读电子邮件时,您设置已阅读标志,然后计算标志。

标签: asp.net graph exchange-server exchangewebservices


【解决方案1】:

Outlook 命名空间需要 Outlook,请改用 EWS Managed API

下面的代码将收集今天收件箱中收到的电子邮件列表。

Using Service = New ExchangeService()
    Dim View As New ItemView(Integer.MaxValue)
    Dim sfc As New SearchFilter.SearchFilterCollection()

    ' Return only emails received from midnight this morning
    sfc.Add(New SearchFilter.IsGreaterThanOrEqualTo(EmailMessageSchema.DateTimeReceived, DateTime.Now.Day))

    ' Get the count 
    Dim totalCount = Service.FindItems(f.Id, sfc, View).TotalCount
End Using

您可能需要查看EWS Impersonation 才能阅读每个邮箱。

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 2011-06-01
    相关资源
    最近更新 更多