Hold that email!


September 19, 2008 – 3:55 pm by JP

    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:

VBA:
  1. Private WithEvents MyItems As Outlook.Items

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

VBA:
  1. Private Sub Application_Startup()
  2. Dim objNS As Outlook.NameSpace
  3. Set objNS = GetNamespace("MAPI")
  4. Set MyItems = objNS.GetDefaultFolder(olFolderInbox).Items
  5. 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.

VBA:
  1. Private Sub MyItems_ItemAdd(ByVal Item As Object)
  2. If TypeOf Item Is Outlook.MailItem Then
  3.   Dim Msg As Outlook.MailItem
  4.   Set Msg = Item
  5.   If Msg.SenderEmailAddress = "jimmy_pena@somewhere.com" Then
  6.     Call SendMsg(Msg, "Hey how are ya!", 10)
  7.     GoTo ExitProc
  8.   End If
  9. End If
  10. End Sub

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

VBA:
  1. Sub SendMsg(ByRef Msg As Outlook.MailItem, sMsg As String, lDelay As Integer)
  2.  
  3. Dim MsgReply As Outlook.MailItem
  4. Dim strOrigMsgSender As String
  5. Dim strOrigMsgSubject As String
  6. Dim dteThen As Date
  7.  
  8. ' from http://www.outlookcode.com/threads.aspx?forumid=3&messageid=840
  9. dteThen = DateAdd("n", lDelay, Now)
  10.  
  11.  
  12.  
  13. ' so we don't have to keep hitting Msg object, set up some varbs
  14. With Msg
  15.   strOrigMsgSender = .SenderEmailAddress
  16.   strOrigMsgSubject = .Subject
  17.   Set MsgReply = .Reply
  18. End With
  19.  
  20. With MsgReply
  21.   .DeferredDeliveryTime = dteThen
  22.   .To = strOrigMsgSender
  23.   .BodyFormat = olFormatHTML
  24.   .Display
  25.   .HTMLBody = "<p>" & sMsg & "</p><br />" & .HTMLBody
  26.   .Send
  27. End With
  28.  
  29. ExitProc:
  30. Set MsgReply = Nothing
  31. 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:

VBA:
  1. Private Sub MyItems_ItemAdd(ByVal Item As Object)
  2. If TypeOf Item Is Outlook.MailItem Then
  3.   Dim iTimeToSend As Integer
  4.   Dim Msg As Outlook.MailItem
  5.   Set Msg = Item
  6.   If Msg.SenderEmailAddress = "jimmy_pena@somewhere.com" Then
  7.     Randomize
  8.     iTimeToSend = Int((10 - 1) * Rnd + 1)
  9.     Call SendMsg(Msg, "Hey how are ya!", iTimeToSend)
  10.     GoTo ExitProc
  11.   End If
  12. End If
  13. 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


Share and Enjoy:
  • StumbleUpon
  • Technorati
  • Digg
  • Google
  • del.icio.us
  • MisterWong

Print This Post Print This Post  |  Email This Post Email This Post  |  Permalink  |  Subscribe to this feed Subscribe now!

Filed Under: Outlook, VBA
Tags:

This post has 201 views since September 19, 2008 – 3:55 pm.
  1. 2 Trackback(s)

  2. Sep 19, 2008: Contextures Blog » Do Not Disturb
  3. Sep 19, 2008: Contextures Blog » Delay Sending Outlook Messages

Post a Comment

To post VBA code in your comment, use [VBA] tags, like this: [VBA]Code goes here[/VBA].





Subscribe without commenting

Keep Reading:

Browse Posts:


« Send links via Outlook email || A simple sheet changing add-in »