RE: Tracking if a message was sent with OL Reference
Hey all, im using a createobject reference (see below) to call an outlook mail message... I wanted to track if it is sent or not so that I can take the final composed message and store it in a database (This is for message tracking from within my application) See code below, any suggestions would be helpful! Thanks!
VB Code:
Dim olMailItem
Dim olApp As Object
Dim objMail As Object
Set olApp = CreateObject("Outlook.Application")
Set objMail = olApp.CreateItem(olMailItem)
Set objMail = olApp.CreateItem(olMailItem)
With objMail
If (strRecipientName <> "") And (IsNull(strRecipientName) = False) Then .To = strRecipientName
.HTMLBody = strMailTemplateInfo
.Subject = "Critical Call IM" & KillZeros(Mid(frmMain.lblTickInfo.Caption, 3, 13)) & " - " & strMsgSubType & " - " & frmMain.txtKnownApps
On Error GoTo DialogOpen
.Display
End With
Re: Tracking if a message was sent with OL Reference
Well you have created two instances of the email item object variable and only need one.
You mean to determine if the user clicked send after the .Display line?
Re: Tracking if a message was sent with OL Reference
your right, I totally did, well the first dim isnt even really used so I can remove that from my code.. But yes that is exactly what I want to do.... basically if the user closes the message, I want it to return to the app saying that the message was closed and not sent... but if they send, I want to capture the body, subject, and sent information before it goes out... The message is sent from a shared mailbox, so I cannot have the application go to the sent items folder and retrieve it... nor would I really want to, I would like to keep all activity as localized as possible
Thanks!
Re: Tracking if a message was sent with OL Reference
Ok, as long as you can place this macro code behind users Outlook VBA class you can track all outgoing email.
VB Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'Write out to a log or save info to a file etc.
End Sub
If not then you can show the message Modally and test for the email object variable still being instanciated. If its not then they closed the inspector window.
VB Code:
.Display vbModal
If TypeName(objMail) = "Nothing" Then
MsgBox "Forgot to send email before closing"
End If
Re: Tracking if a message was sent with OL Reference
I would actually like to stay away from putting VBA in outlook, I want all coding to be completely on my application side
is there a way that I can get the message contents out of it when it gets sent?