Why does Attachments.Count return 0 on incoming mail with attachments?

后端 未结 2 1244
攒了一身酷
攒了一身酷 2020-12-20 09:38

I\'m trying to save attachments automatically to a local folder using Outlook 2010.

It works when I first create the rule and apply it to all inbox. It doesn\'t work

相关标签:
2条回答
  • 2020-12-20 10:23

    Replace your Outlook Rule with Items.ItemAdd Event (Outlook) see example

    Private WithEvents Items As Outlook.Items
    Private Sub Application_Startup()
        Dim olNs As Outlook.NameSpace
        Dim Inbox  As Outlook.MAPIFolder
    
        Set olNs = Application.GetNamespace("MAPI")
        Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
        Set Items = Inbox.Items
    End Sub
    
    Private Sub Items_ItemAdd(ByVal Item As Object)
        If TypeOf Item Is Outlook.MailItem Then
            saveAttachtoDisk Item ' call sub
        End If
    End Sub
    

    Application.Startup Event (Outlook) and Items.ItemAdd Event (Outlook)


    Items.ItemAdd Event (Outlook) Occurs when one or more items are added to the specified collection. This event does not run when a large number of items are added to the folder at once. This event is not available in Microsoft Visual Basic Scripting Edition (VBScript).


    Application.Startup Event (Outlook) Occurs when Microsoft Outlook is starting, but after all add-in programs have been loaded.


    0 讨论(0)
  • 2020-12-20 10:34

    I finally found out the reason. It seems that using IMAP is not an option if I want to save attachments automatically. I switched to POP3 and everything works just fine.

    0 讨论(0)
提交回复
热议问题