Hi Everyone,
I've been trying to find a solution for the following example, I send an email to "abc@gmail.com" once sent take the email from the sent folder move to delete folder and permanently delete the item. And this is for email only going to "abc@gmail.com"
I've looked around and the only code I could find is the following but its not working for me. I'm not sure if i have to create a class module, and regular module in vba.
Any help would be much appreciated.
I've been trying to find a solution for the following example, I send an email to "abc@gmail.com" once sent take the email from the sent folder move to delete folder and permanently delete the item. And this is for email only going to "abc@gmail.com"
I've looked around and the only code I could find is the following but its not working for me. I'm not sure if i have to create a class module, and regular module in vba.
Any help would be much appreciated.
Code:
Public WithEvents mySentItems As Outlook.Items
Public WithEvents myDeletedItems As Outlook.Items
Public Sub Application_Startup()
Set mySentItems = Outlook.Session.GetDefaultFolder(olFolderSentMail).Items
Set myDeletedItems = Outlook.Session.GetDefaultFolder(olFolderDeletedItems).Items
End Sub
Private Sub mySentItems_ItemAdd(ByVal Item As Object)
Dim OutgoingMail As Outlook.MailItem
Dim SentTo As String
Set OutgoingMail = Item
SentTo = OutgoingMail.To
Debug.Print Time
Debug.Print SentTo
If SentTo = "abc@gmail.com" Then
OutgoingMail.Delete
End If
End Sub
Private Sub myDeletedItems_ItemAdd(ByVal Item As Object)
Dim OutgoingMail As Outlook.MailItem
Dim SentTo As String
Set OutgoingMail = Item
SentTo = OutgoingMail.To
Debug.Print Time
Debug.Print SentTo
If SentTo = "abc@gmail.com" Then
OutgoingMail.Delete
End If
End Sub