Foxtable(狐表)用户栏目专家坐堂 → vb.net 代码转换请教


  共有148人关注过本帖平板打印复制链接

主题:vb.net 代码转换请教

帅哥哟,离线,有人找我吗?
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107873 积分:548728 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2024/6/28 13:41:00 [只看该作者]

大概

Public Class Program
    Shared outlookApp As New Microsoft.Office.Interop.Outlook.ApplicationClass()
    Shared ns As [NameSpace]
    
    Public Shared Sub Main()
        msgbox("start to monitor new emails")
        ns = outlookApp.GetNamespace("MAPI")
        AddHandler outlookApp.NewMailEx , AddressOf outlookApp_NewMailEx
        AddHandler outlookApp.NewMail , AddressOf outlookApp_NewMail
        
        While True
        End While
    End Sub
    
    Private Shared Sub outlookApp_NewMail()
        msgbox("a new message comes: new email")
    End Sub
    
    Private Shared Sub outlookApp_NewMailEx(ByVal EntryIDCollection As String)
        msgbox("a new message comes")
        AnalyzeNewItem(EntryIDCollection)
    End Sub
    
    Private Shared Sub AnalyzeNewItem(ByVal entry As String)
        Dim inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
        Dim allmails As List(Of Microsoft.Office.Interop.Outlook.MailItem) = New List(Of Microsoft.Office.Interop.Outlook.MailItem)()
        
        For Each item In inbox.Items
            
            If TypeOf item Is Microsoft.Office.Interop.Outlook.MailItem Then
                Dim mail = TryCast(item, Microsoft.Office.Interop.Outlook.MailItem)
                allmails.Add(mail)
            End If
        Next
        
        Dim latest = allmails.Max(Function(s) s.ReceivedTime)
        Dim latestMailItem = allmails.FirstOrDefault(Function(s) s.ReceivedTime = latest)
        
        If latestMailItem IsNot Nothing Then
            msgbox(latestMailItem.Subject)
            msgbox(latestMailItem.[To])
            msgbox(latestMailItem.SenderName)
            msgbox(latestMailItem.ReceivedTime)
            msgbox(latestMailItem.Body)
        End If
    End Sub
End Class


 回到顶部