Hold that email!

September 19, 2008JPNo CommentsRate This ArticlenewLinks to this article


    In Delay Sending Outlook Messages, Debra Dalgleish writes about deferring delivery times for Outlook messages:

You hit Send, then realize you forgot the attachment. Or you misspelled the recipient’s name. Or you used Reply All, when you only wanted the message to go to one person. None of these things have ever happened to me (well hardly ever), but you might have been less fortunate.

    Outlook 2003 and 2007 have the ability to hold all sent messages for a pre-determined length of time. The link to MS Outlook 2007's instructions are in Debra's post.

    If you set this option under "Rules And Alerts", it can apply all outgoing messages equally. You can also set this on a per-message basis by selection "Options" in an open email, and putting the date and time in the appropriate boxes.

    There are good reasons for doing this, for example, if you respond to a certain email too quickly, it sets unreasonable expectations for future responses. You don't want to give your recipients (especially your boss) the appearance that you are sitting at your desk doing nothing; that's a sure way to get bombarded with emails. You've trained them to expect a fast response, so when you respond "normally" next time, to them it will appear slow. Let the misery begin!

    You can also use this feature to manage your email and even make it appear that you are at your desk duly reading and responding to emails. You can craft pseudo-autoresponses that make it appear you've actually read the email! All by just deferring the delivery time. I call them "pseudo" because a real autoresponse comes in almost instantly (like Out Of Office), making it appear computer-generated, cold, and making you feel like your email is definitely unread. But by delaying the response, we can fool the recipient into thinking their email is actually being read. ;)

    We can defer emails programmatically in several ways:

  • during the execution of another routine that requires emails to be sent out,
  • on every email that goes out, defer delivery by X number of minutes/hours/days/etc; or,
  • make deferral conditional on other conditions, such as who the sender was, what the subject is, etc.

    I'll demonstrate the second way here. First you paste the following at the top of your ThisOutlookSession module, in the (Declarations) section:

Private WithEvents MyItems As Outlook.Items

    Then we need to initialize the event variable above by placing the following code in the Startup event:

Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
Set MyItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

    This will act as a monitor on the default Inbox. Here is the event code that will actually do the work when a new email is received. The ItemAdd event is triggered whenever a new item is received or placed in the default Inbox.

Private Sub MyItems_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
  Dim Msg As Outlook.MailItem
  Set Msg = Item
  If Msg.SenderEmailAddress = "jimmy_pena@somewhere.com" Then
    Call SendMsg(Msg, "Hey how are ya!", 10)
    GoTo ExitProc
  End If
End If
End Sub

    Whenever an email is received (a MailItem Object), we call the sub SendMsg, which is going to provide the response.

Sub SendMsg(ByRef Msg As Outlook.MailItem, sMsg As String, lDelay As Integer)

Dim MsgReply As Outlook.MailItem
Dim strOrigMsgSender As String
Dim strOrigMsgSubject As String
Dim dteThen As Date

' from http://www.outlookcode.com/threads.aspx?forumid=3&messageid=840
dteThen = DateAdd("n", lDelay, Now)



' so we don't have to keep hitting Msg object, set up some varbs
With Msg
  strOrigMsgSender = .SenderEmailAddress
  strOrigMsgSubject = .Subject
  Set MsgReply = .Reply
End With

With MsgReply
  .DeferredDeliveryTime = dteThen
  .To = strOrigMsgSender
  .BodyFormat = olFormatHTML
  .Display
  .HTMLBody = "<p>" & sMsg & "</p><br />" & .HTMLBody
  .Send
End With

ExitProc:
Set MsgReply = Nothing
End Sub

    This sub takes three arguments:

  • The original message (as a MailItem Object),
  • A message we want to send back, and
  • The amount of time (in minutes) to defer the message.

    Test it out and you will see the deferred delivery time is set to the same date as the email, with 10 minutes added to the delivery time.

    We can get very clever with this as well. Instead of a set time of 10 minutes, we can make it random so our recipient can't tell it's a machine response. Change the ItemAdd Event as follows:

Private Sub MyItems_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
  Dim iTimeToSend As Integer
  Dim Msg As Outlook.MailItem
  Set Msg = Item
  If Msg.SenderEmailAddress = "jimmy_pena@somewhere.com" Then
    Randomize
    iTimeToSend = Int((10 - 1) * Rnd + 1)
    Call SendMsg(Msg, "Hey how are ya!", iTimeToSend)
    GoTo ExitProc
  End If
End If
End Sub

    The Randomize function shuffles the deck, then we assign a random number between 1 and 10 to the Integer variable iTimeToSend. This will defer the delivery time of the email to a random time 1 to 10 minutes into the future. In other words, some replies will go out in 5 minutes, others in 7 minutes, 2 minutes, and so on. For full effect, make sure you use a conversational tone, and use the sender's first name (Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") – 1)) to personalize the response.

    This can get as complicated as you want. You can set up string constants that represent different types of replies (the sMsg variable) and use Select Case statements to call the SendMsg function with different parameters depending on the sender, keywords in the subject, number of attachments, etc. Let your mind wander and I'd be glad to see the results. I'd love to see someone develop a fake AI that sends back responses like "That's interesting, tell me more!" and "Oh really?" to keep an email conversation going all on its own.

Enjoy,
JP

About JP
I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space if you want to learn more about VBA. Keep Reading »

↑ Scroll to top
Previous Post:

Next Post:


2 Trackback(s)

Check out what others are saying about this post...
  1. [...] Update (2008-Sep-19): JP has written an article describing how to delay Outlook messages with programming. [...]

  2. [...] Update (2008-Sep-19): JP has written an article describing how to delay Outlook messages with programming. [...]

Speak Your Mind

Tell us what you're thinking...

Certain comments (including first-time comments) are subject to moderation and will not appear immediately. Please view the Comment Policy for more information. To post VBA code in your comment, use tags like this: [cc lang='vb']Code goes here[/cc].




Site last updated August 24, 2010 @ 5:56 pm