More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

forum 28-Aug-2014 08:21

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

Login Password
Remember me
Register | Send my password
    Page [ 1 ]  
 Basic Outlook Printer Friendly Version
Working with Outlook items, folders, recipients; dealing with security; writing event handlers
Topic
check if email Sent
I have some code that checks if an attachment is in an email and pops up a message if it id missing. I would like to perform an action if the email is sent successfully. How might i add some code to allow that?

I tried checking if messageitem.sent became true during this procedure but it did not.
Thanks

Neil

Original code below.
----------------
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim m As Variant
Dim strBody As String
Dim intIn, intLength As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
'
On Error GoTo ErrorHandler
'
'You may have a picture or vCard in your email signature that you
'don't want to be counted when checking for attachments. If so, then
'edit the following line to make intStandardAttachCount equal the
'number of files attached in your signature.
intStandardAttachCount = 0
'
'CHECK #1: Check for a blank subject line
If Item.Subject = "" Then
'Extra spaces added to the messages just to
'keep them centered and pretty
m = MsgBox("The subject line is blank... " & _
vbNewLine & vbNewLine & _
"Do you still want to send this message? ", _
vbYesNo + vbDefaultButton2 + vbExclamation + vbMsgBoxSetForeground, "Blank Subject")
If m = vbNo Then
Cancel = True
GoTo ExitSub
End If
End If
'
'CHECK #2: Check for a missing attachment
intIn = 0
strBody = LCase(Item.Subject) & LCase(Item.Body)
'If the message is a reply or forward, then the macro will
'not search for the strings in the original message. Anything
'below the "from:" line is ignored
intLength = InStr(1, strBody, "from:")
If intLength = 0 Then intLength = Len(strBody)
'
'Add lines for every string you want to check, including other
'languages, etc. Partial strings are fine. For example, "attach"
'will match "attached" & "attachment"
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "attach")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "file")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "enclosed")
'
intAttachCount = Item.Attachments.Count
If intIn > 0 And intAttachCount <= intStandardAttachCount Then
m = MsgBox("It looks like you forgot to attach a file... " _
& vbNewLine & vbNewLine & _
"Do you still want to send this message? ", _
vbYesNo + vbDefaultButton2 + vbExclamation + vbMsgBoxSetForeground, "Attachment Missing?")
If m = vbNo Then
Cancel = True
GoTo ExitSub
End If
End If
'
'CHECK #3: Check for meeting requests with no location
If Item.Class = olMeetingRequest Then
If InStr(1, Item.Body, "Where:", vbTextCompare) = 0 Then
m = MsgBox("The meeting location is blank... " _
& vbNewLine & vbNewLine & _
"Do you still want to send this meeting invite? ", _
vbYesNo + vbDefaultButton2 + vbExclamation + vbMsgBoxSetForeground, "Blank Location")
If m = vbNo Then
Cancel = True
GoTo ExitSub
End If
End If
End If
'
ExitSub:
Set Item = Nothing
strBody = ""

Exit Sub
'
ErrorHandler:
MsgBox "Send Checker" & vbCrLf & vbCrLf _
& "Error Code: " & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo ExitSub
 
End Sub

  25-Feb-2013  12:14
  25-Feb-2013  12:36   
Try changing the end of your code to this:

ExitSub:
Set Item = Nothing
strBody = ""
MsgBox "All validations passed. Send should be successful if your additional code is good. Add it here." ' <----
Exit Sub
'
ErrorHandler:
MsgBox "Send Checker" & vbCrLf & vbCrLf _
& "Error Code: " & Err.Number & vbCrLf & Err.Description
Err.Clear
'GoTo ExitSub ' <---
Set Item = Nothing ' <---
strBody = "" ' <---

End Sub
  07-Mar-2013  05:08   
Thanks

I got a working system using that info.

I just wondered if i can add a number into any form of custom field in an email (outlook 2003) that will persist so that it can be viewed if it is sent back?

At present i am using vba to alter the subject line to include a number code preceded by a tilde so i can extract it later. It looks a bit odd though and could be deleted.

Regards


Neil

 
    Page [ 1 ]