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:
Name | Value | Description |
---|---|---|
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.
When our admins downgraded our mail from Notes to Outlook, they were able to hook up the plumbing on the backend so that any code in Notes that sends mail still works.
I doubt it was easy, but I’m guessing it wasn’t crazy hard either or they wouldn’t have bothered.
Tim, we have that kind of a setup as well, but it’s clunky, requiring the setup to be “odd”. It’s not problem for messages sent from the server itself, but for ones created by actions in the Notes client, it is a problem.
In our transition, many users have moved over to Outlook but not been reconfigured properly, so these emails weren’t reliably sent. Additionally, they’d come from a central mail file instead of from the user whose action spurred the email.
This has a couple of other advantages over having it done on the back end.
First, it shows up in the Sent mail for the user. In our company, they always want to be able to find when they actually sent the message. You can’t do that if it’s sent from Notes itself.
The second one is ‘forward compatibility’. When we move the application off of Notes, or when I want to do the same thing in an application that was never in Notes, I have a code snippet to build upon.
I failed to mention that we have over a 1000 apps. Editing each sub containing doc.send in each of these databases would take forever.
BTW, When “needing proof of being sent”, needing to get into the sender’s file to find the email has issues. In our code, we simply BCC every single email to a mail-in database with restricted access. When I get a “I didn’t get notified” complaint, I can usually prove otherwise by going into that database and producing the email. Just a thought.
Our users are spread worldwide and they don’t come to me for proof of who sent what, thankfully. I’d have to be on call 24/7 in order to handle that!
Since the original implementation of notifications from applications was via opening new messages in the UI, rather than sending them on the back end, they always had a ‘sent’ copy. So, when I started having more things sent quietly in the background, there was considerable consternation. They were used to being able to check their own mail file to prove that they notified someone. So, this restores a capability while relieving the user of the responsibility of clicking ‘send’.
There are only a few instances where we’ll be replacing doc.Send, but many places where the formula language that generates an email will have to be replaced with a mailto link ( https://lostinxpages.com/2017/06/02/progammatically-opening-a-mailto-link-from-the-notes-client/ ) as we work to rely on the Notes client less (that one is also mail client agnostic, which is even better).
As always, your mileage might vary.