Validate Email Sent

Comfy

Well-known Member
Joined
Dec 21, 2009
Messages
3,386
Hi Boardies,

I have a workbook that sends emails. I'm trying to create a log table to record if any emails weren't sent.

The problem that I'm encountering is that the code runs too quickly for the Outlook App.

I'm using Outlook 2016 in Win10 and Outlook is connected via Microsoft Exchange to Hotmail.

This is what I'm using to check Draft (olDefaultFolder 16)/Outbox (olDefaultFolder 4)/Sent (olDefaultFolder 5) folders :

Code:
If CheckSent(oApp, 16, lRow.Range(1, LO1Col3Index), lRow.Range(1, LO1Col2Index) & fExt) Or CheckSent(oApp, 4, lRow.Range(1, LO1Col3Index), lRow.Range(1, LO1Col2Index) & fExt) Or CheckSent(oApp, 5, lRow.Range(1, LO1Col3Index), lRow.Range(1, LO1Col2Index) & fExt) Then
        Call AddLogRow(LogLO, Now(), "Email Success", lRow.Range(1, LO1Col2Index) & fExt & " Succesfully emailed")
    Else
        Call AddLogRow(LogLO, Now(), "Email Fail", "Could not find " & lRow.Range(1, LO1Col2Index) & fExt & " in sent items.")
    End If

And the CheckSent Function is:

Code:
Function CheckSent(oApp As Object, fIndex As Integer, Recip As String, attachname As String) As Boolean
Dim oFolder As Object 'https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/folders-object-outlook
Dim oItems As Object
Dim fFilter As String
Dim mItems As Object


Set oFolder = oApp.GetNamespace("MAPI").GetDefaultFolder(fIndex)
'fFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:attachmentfilename" & Chr(34) & " LIKE '%" & attachname & "%'"
fFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x3704001E" _
    & Chr(34) & " ci_phrasematch " & "'" & attachname & "'"
Set mItems = oFolder.Items.Restrict(fFilter)
If mItems.Count = 0 Then
CheckSent = False
Else
CheckSent = True
End If
End Function

At the moment this is just looking for mailitems where attachments have a certain file name, but once working I'd like to include recipient email also.


If I step through the code slowly this function correctly returns mailitems found in the sent folder. But if run normally it fails, now whether that's because it's too fast or I have the wrong code for the draft and outbox folders I do not know.

/Comfy
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top