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



Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, December 26, 2018

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250