VB.Net Tutorial/Windows/Outlook — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:56, 26 мая 2010

Outlook Email watcher

Imports System

public class MainClass
   Private Shared WithEvents objOMW As OutlookMessageWatcher
   public Shared Sub Main
        objOMW = New OutlookMessageWatcher()
   End Sub
    Private Shared Sub objOMW_EmailArrived(ByVal From As String, _
            ByVal Subject As String, _
            ByVal Message As Outlook.MailItem) _
            Handles objOMW.EmailArrived
        Console.WriteLine(Subject)
    End Sub
End class
Public Class OutlookMessageWatcher
    Private WithEvents objInboxItems As Outlook.Items
    Private objOutlook As Outlook.Application
    Public Event EmailArrived(ByVal From As String, _
        ByVal Subject As String, _
        ByVal Message As Outlook.MailItem)
    Public Sub New()
        objOutlook = New Outlook.Application()
        objOutlook.Session.Logon(NewSession:=False)
        objInboxItems = objOutlook.Session.GetDefaultFolder (Outlook.OlDefaultFolders.olFolderInbox).Items
    End Sub
    Private Sub objInboxItems_ItemAdd(ByVal Item As Object)Handles objInboxItems.ItemAdd
        Dim objNewMail As Outlook.MailItem
        objNewMail = CType(Item, Outlook.MailItem)
        RaiseEvent EmailArrived(objNewMail.SenderName, objNewMail.Subject, objNewMail)
    End Sub
End Class