Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Track when Outlook e-mail sent

Posted on 2014-04-29
3
Medium Priority
?
1,248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 750 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 71

Accepted Solution

by:
Qlemo earned 750 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

721 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