Today, most of us have smartphones that can send/receive email from anywhere. But what if you don’t have a smartphone? Or perhaps you do have a smartphone, but your company has a policy that prohibits accessing the corporate email system from it. Let’s say that you have a cell phone, not a smartphone, or you have a personally owned smartphone, and that you will be away from your desk for a while. While you’re out, you’d like to know if a particular message has arrived. That’s the situation one commenter found himself in and approached me about.
Outlook does have a built-in solution for this scenario, which is to use a rule that sends a message based on a condition. The rule watches for messages that meet a certain condition. When one arrives, it would create an email and send it to the email account on your smartphone, if that’s what you have, or as a text message to a regular cell phone. The problem with this solution is that you have to use a message template and templates don’t allow you to pass on any of the message’s details. Assume that you want a notification for any message coming from a person on your project team. A message from one of them comes in and the rule sends the notification. Because the notification is a template, you don’t have any clue who sent the message that triggered the rule, or what the subject is. All you know is that you got a message from someone on your project team. That’s not very useful.
The solution to this scenario is a macro. You’ll still use a rule to watch for the subject messages, but instead of the rule sending a canned message, the macro will send a message that includes the sender and subject information of the message that triggered the rule. The macro also allows you to specify whether you want the notification as an email or as a text message. Actually both will go out as an email, the difference being the format and length of the notification. Emails will go in HTML format while a text message will go as plain text and will be briefer and to the point. Consult this Wikipedia article for a list of email-to-SMS gateways. It shows how to format the email address for your cellular service provider. If your cellular provider isn’t listed, then you’ll either have to have a smartphone and use the email option, or find an email-to-SMS gateway you can use.
Adding the code to Outlook.
- Start Outlook
- Press ALT+F11 to open the Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects
- If not already expanded, expand Modules
- Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
- Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as needed. I included comments where changes are required
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
Sub SendNotification(Item As Outlook.MailItem) 'On the next line set the value to True if you want the notification as an SMS, False if you want it as an email Const SEND_AS_SMS = True 'On the next line enter the email address of your SMS account (if using SMS) or of your smartphone's email account Const EMAIL_ADDR = "email@example.com" Dim olkMsg As Outlook.MailItem Set olkMsg = Application.CreateItem(olMailItem) With olkMsg .Recipients.Add EMAIL_ADDR .Recipients.ResolveAll If SEND_AS_SMS Then .BodyFormat = olFormatPlain .Subject = "New Msg" .Body = Item.SenderName & vbCrLf & Item.Subject Else .BodyFormat = olFormatHTML .Subject = "New Message" .HTMLBody = "You just received a message from <b>" & Item.SenderName & "</b> with a subject of <b>" & Item.Subject & "</b>" End If .Send End With Set olkMsg = Nothing End Sub
Using this solution.
- Create a rule that fires for the messages you want notifications for.
- Set the rule’s action to run a script and select this macro as the one to run.