Articles → VBA FOR OUTLOOK → Delete All Emails From Outbox In Outlook If Older Than One Day In VBScript
Delete All Emails From Outbox In Outlook If Older Than One Day In VBScript
Dim oFolder, oItem, oNamespace, oOutlook
' OUTBOX Items folder Code.
Const OUTBOX = 4
'Create Outlook Application object and make it visible
Set oOutlook = CreateObject("Outlook.Application")
Set oNamespace = oOutlook.GetNamespace("MAPI")
' Open default account (will fail if Outlook is closed)
oNamespace.Logon "Default Outlook Profile", , False, False
Set oFolder = oNamespace.GetDefaultFolder(OUTBOX)
For Each oItem In oFolder.Items
intDateDiff = DateDiff("d", oItem.SentOn, Now)
If intDateDiff > 1 Then
oItem.Delete
End If
Next
Set oFolder = Nothing
Set oNamespace = Nothing
Set oOutlook = Nothing