One of the greatest hurdles we’ve had in our transition from being a Notes mail shop to an Outlook mail shop remaining a Notes application shop is automated emails. When someone clicks a button to approve a document in a workflow, I want the system to quietly notify the pertinent parties without bothering the user.
Before I arrived, none of our applications did that. Every time someone wanted an email to accompany the request for approval, an email was opened in the Notes client using formula language. The code did assign the recipients and add text with a doclink, but the user had to click ‘Send’ for the message to go onward. This did allow them to add explanatory text and choose to route the message to a different approver if someone was not available, so it did have advantages. However, not every message ought to sent that way and we can keep the user inside our application by popping up dialogs to customize or select different recipients, or… whatever flexibility we’d like to provide.
So, a number of the applications I’ve designed, or modified from the original, send notices via Notes mail, generated quietly in the background by LotusScript. 2016 rolls around and our organization makes a strategic move away from Notes mail and into Outlook. I spent a year thinking there was no way for me to keep those notifications without dancing around about Notes mail files and replication. The other day, I wondered if I could use OLE to create the Outlook messages and send them without the user needed to intervene. Shockingly, it didn’t even take me a day to figure out how to do it.
The hardest part was figuring out that passing in 0 for the item type needed to specifically be an integer, not just a zero. If figured this out when I created a task using 3. Since it understood that 3 was an integer, I just created itemType as an integer and then 0 really was 0. (Got the clue from someone’s commented code on Stack Overflow, of course)
Here’s the list of Outlook items you can create, with links so you can examine the events, properties and methods:
|olAppointmentItem||1||An AppointmentItem object.|
|olContactItem||2||A ContactItem object.|
|olDistributionListItem||7||A DistListItem object.|
|olJournalItem||4||A JournalItem object.|
|olMailItem||0||A MailItem object.|
|olNoteItem||5||A NoteItem object.|
|olPostItem||6||A PostItem object.|
|olTaskItem||3||A TaskItem object.|
%REM Agent Send Outlook Mail Created Sep 12, 2017 by David Navarre Description: This Agent creates and sends an Outlook mail message in the background %END REM Option Public Option Declare Sub Initialize Dim outlook As Variant Dim message As Variant Dim itemType As Integer Dim reason As String On Error GoTo errorhandler Set outlook = CreateObject("Outlook.Application") ' 0 is mail item ' itemType = 0 Set message = outlook.CreateItem(itemType) message.To = "David_Navarre@company.com" message.Subject = "This is my test" message.HTMLBody = "<b>Body bolded</b> and some not" message.Send exiting: Exit Sub errorhandler:' report all errors in a messagebox ' reason = "Error #" & CStr (Err) & " (" & Error & ") on line " & CStr (Erl) MessageBox reason, 16, "Error" Resume exiting End Sub
The most amusing thing to me is that I got my initial clue from a post made way back in 2006. Sometimes, I feel like I’m starting all over again. I guess that’s a good thing, because learning new stuff was always fun (this was too!) and not as intimidating as it sometimes seems when I think about having to learn something new. It’s been nice to be in the upper branches of the knowledge tree, but the truth is that what always separated me from other folks was not what I already knew, but how fast I could learn something new.