Solved

Track when Outlook e-mail sent

Posted on 2014-04-29
3
1,192 Views
Last Modified: 2014-05-01
I have an MS Access database that the user can create an Outlook message to be sent, but I also need to know if the user actually sends the e-mail. Can someone direct or assist me in how to record in an Access table the date the e-mail was sent?

Below is my code for creating the e-mail:


Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim appOutlook As Outlook.Application
Dim msg As Outlook.MailItem
Dim strEmail As String
Dim msgbody As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblEMAIL_TMP")
Set appOutlook = New Outlook.Application
        strEmail = Nz(rst![DC1EMAIL])
Set msg = appOutlook.CreateItem(olMailItem)
         msg.To = strEmail
         msg.Subject = "Survey "
         msg.BodyFormat = olFormatHTML
         msg.Display
         msgbody = "Dear" & " " & rst![DC1TL] & " " & [DC1LN] & "," & vbCrLf
         msgbody = msgbody & " " & vbCrLf
         msgbody = msgbody & "We would greatly appreciate you taking a few minutes to complete a short survey regarding the Training Visit that recently took place with your dealership. " & vbCrLf
         msgbody = msgbody & "Your candor and feedback will help us improve our processes." & vbCrLf
         msgbody = msgbody & " " & vbCrLf
         msgbody = msgbody & "Please note that your responses are anonymous, unless you choose otherwise.  Thank you in advance for your time. " & vbCrLf
         msgbody = msgbody & " " & vbCrLf
         msgbody = msgbody & "Please click here to begin the survey:  https://www.surveymonkey.com/s/TVFY14 "
         msg.Body = msgbody
         msg.Display
         'msg.Send  
ErrorHandlerExit:
   rst.Close
   Set rst = Nothing
   Set appOutlook = Nothing
   Exit Sub

ErrorHandler:
   'Outlook is not running; open Outlook with CreateObject
   If err.Number = 429 Then
      Set appOutlook = CreateObject("Outlook.Application")
      Resume Next
   Else
      MsgBox "Error No: " & err.Number _
         & " in EMailAllContacts procedure" _
         & "; Description: " & err.Description
      Resume ErrorHandlerExit
   End If

    Screen.PreviousControl.SetFocus
    DoCmd.RunCommand acCmdAutoDial

Exit_cmdEMAIL_NO_Click:
    Exit Sub

Err_cmdEMAIL_NO_Click:
    Resume Next
    Resume Exit_cmdEMAIL_NO_Click
End Sub
0
Comment
Question by:castlerj
3 Comments
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 250 total points
ID: 40030754
...Can I presume that a delivery receipt is not what you are looking for here?
ex.: msg.OriginatorDeliveryReportRequested = True

You may need to clearly define "Send"
When the user clicks "Send"?
When the email is actually "sent" (some systems store the email in the outbox to be sent later)?
I don't know of on easy way to track when an email is actually sent.

To be sure, the info on all emails "sent" is kept in your "Sent Items" folder in outlook.
You can open this folder and sort by the date sent, to see the most recently sent email(s).

You can also use Access to link to your sent items folder, ...then create a query to look at today's sent emails:
(Something like this ugly, but working query.). ;-):
SELECT CDate(Format([sent],"mm/dd/yyyy")) AS JustDate, [Sent Items].Sent, [Sent Items].Contents, [Sent Items].Subject, [Sent Items].To, [Sent Items].[Sender Name]
FROM [Sent Items]
WHERE (((CDate(Format([sent],"mm/dd/yyyy")))=Date()));
...Or simply use this linked table directly...

But it is not a simple task to "trigger" anything to happen (add a record to a table in Access) if a record is added to the sent items folder.

Your code creates an email, ...but emails do not really have a Primary Key attached to them, so it is difficult to track a specific email, (create a table entry when they are "sent"), after they are created.

Hope this helps...

JeffCoachman
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
ID: 40030916
You can use the MailItem.EntryID (a hexdigits string) of the mail as a PK. It is generated by Outlook to uniquely identify stored or sent messages (either is sufficient).
As then send process is asynchronous, even if you just want to know at which time Outlook queued the message to its outbox, you either need to poll the generated MailItem object for the MailItem.Send boolean, or implement an event trigger for Send (which might not be possible with dynamic code - didn't try).
0
 

Author Closing Comment

by:castlerj
ID: 40035674
Good advice on both; I tried the following and it seems to work:
Added - Dim rst1 As DAO.Recordset
Set rst1 = Me.RecordsetClone
    rst1.Edit
    rst1!DSSENT = Now
    rst1.Update

ErrorHandlerExit:
   rst.Close
   rst1.Close
   Set rst = Nothing
   Set rst1 = Nothing
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
how to add IIS SMTP to handle application/Scanner relays into office 365.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now