1

I've got given the crazy task of writing a custom rule for Outlook that affects emails that does not have an attachment . Currently in the rules wizard there is an option that targets emails that does have an attachment but not the other way round, strange...

Also worth saying here that I've never written a line of Visual Basic ever! But it's just a little rule, how difficult can it be.

This is what I have currently:

Dim WithEvents objInbox As Outlook.Items

Private Sub Application_Startup()
    Set objInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub objInbox_ItemAdd(ByVal Item As Object)

    ' If the mail doesn't contain an attachment
    If Item.Attachments.Count = 0 Then

          ' Chirp chirp..

    End If

End Sub

An empty if statement.. But basically all I have to do now is call some "delete" function on the "Item" object. Which would then delete the email if it doesn't have an attachment, easy.. I'm used to writing Java and C#, just fyi

Any pointers out there?

4

1 回答 1

1

您需要先将Item对象转换为 aMailItem然后调用MailItem.Delete. 可以表示多个类,例如AppointmentItem, TaskItem,JournalItem等。

Outlook.MailItem mailItem = Item as Outlook.MailItem;
if (mailItem != null)
{
     mailItem.Delete();
}
于 2012-08-27T13:02:00.733 回答