Our company has been transitioning from Notes mail to Outlook for a little while. One of the hurdles for me has been getting Notes to send mail when the user no longer has a Notes mail file and also wants to send any editable emails via the Outlook client. Today, I’d like to have a look at my latest solution to opening those editable emails in the Outlook client.
If you try using @URLOpen or ws.URLOpen, you’ll find that despite having set the default email to Outlook, Notes insists on opening a Notes document to send the mail. If you put the mailto link into a browser, it opens in the default mail client, Outlook, formatted properly. If you programmatically open a http link, it opens in the default browser. Yet, frustratingly, it won’t take that same mailto link that works in the browser and open it from LotusScript or a formula. So, we have to cheat.
mailto syntax
As a quick review, mailto links are actually very simple.
There are five components to the link, but none are required.
mailto:person@company.com Simply list the recipients email addresses. Outlook seems to prefer that you separate them with semi-colons, though most syntax guides suggest commas.
The other four are passed as parameters in the query string. So, before you use any of them, you have to use a question mark to separate the query string from the URL, then separate each parameter with an ampersand (&).
cc=joe@company.com or bcc=jill@company.com You can add carbon-copy folks or blind-copy folks in the same way.
subject=That%20issue The subject line should be encoded so that there are no spaces and any unusual characters pass through to the email rather than disrupt the syntax of the query string.
body=The%20contents%20of%20email The body is, of course, the most important thing to us and we can simply compute the values to be used. Links back to Notes documents to be opened in the Notes client can even be used, so long as you provide a proper notes:// URL.
Hard coded example
If we create a HTML document, store it locally and open it programmatically, it will execute any javascript we’ve got on the page as browsers ought to do. So, we can make it open the mailto link if our page has the following:
<script type="text/javascript"> subject = "Change Order for your approval"; body = "Your approval has been requested for changes made... "; body = body + "%0A%0A"; body = body + "Please review these changes and approve, provide comments, or request more time to review within five business days of this notification. Otherwise, the change will be considered approved as per DAI policy."; body = body + "%0A%0A"; body = body + "The pending change approval form and links to draft documents can be found here: "; body = body + "%0A"; body = body + "Notes:///852580E9007624A0/0/B82A2F4ABF0D56818525808400601DBE"; mailtoString = "mailto:david_navarre@company.com?subject=" + subject + "&body=" + body; window.open(mailtoString)</script>
Sample code
So, all we have to do is generate the mailtoString, put it into a new HTML document and open it via NotesUIWorkspace.URLOpen to get our document to open and popup the Outlook client, populated with the correct information.
Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim thisdb As NotesDatabase Dim uidoc As NotesUIDocument Dim approver As Variant Dim approverNames As String Dim i As Integer Set thisdb = session.CurrentDatabase Set uidoc = ws.CurrentDocument Set doc = uidoc.Document For i = 1 To 6 approver = doc.getItemValue( "Approver"&i ) If i = 1 Then approverNames = approver (0) Else If ( approver (0) <> "" ) Then approverNames = approverNames & ";" & approver (0) End If End If Next Dim subject As String Dim body As String Dim mailtoString As String Dim changeOrderNumber As Variant changeOrderNumber = doc.getItemValue ("CONum" ) subject = "Change Order " & changeOrderNumber (0) & " for your approval in " & thisdb.Title subject = Replace ( subject, " ", "%20" ) body = "Your approval has been requested for changes made using " & changeOrderNumber (0) & " in " & thisdb.Title body = body & "%0A%0A" body = body & "Please review these changes and approve, provide comments, or request more time to review within five business days of this notification. Otherwise, the change will be considered approved as per DAI policy." body = body & "%0A%0A" body = body & "The pending change approval form and links to draft documents can be found here: " body = body & "%0A" body = body & "Notes:///" & thisdb.ReplicaID & "/0/" & doc.UniversalID body = Replace ( body, " ", "%20" ) mailtoString = "mailto:" & approverNames & "?subject=" & subject & "&body=" & body Dim fileName As String Dim dataDirectoryPath As String Dim url As String Dim fileNumber As Integer fileNumber = 1 dataDirectoryPath = session.Getenvironmentstring("Directory", True) fileName = dataDirectoryPath & "\mailto.htm" Open fileName For Output As fileNumber Print # fileNumber, {<script type="text/javascript">} Print # fileNumber, {mailtoString = "} & mailtoString {"} Print # fileNumber, {window.open(mailtoString)</script>} Close # fileNumber url = "file:///" & fileName Call ws.Urlopen(url) End Sub