Send Notes mail from an XML call

So I had a few requests recently on how to send a mail, via Notes, from Visual Basic. I responded with the typical answer for developers to use the Notes COM interface, with the option to use the LDAP service for directory information. The problems with the COM interface are that it is Win32 only, and it requires a local Notes install. This would not be a problem if the messages always came from a workstation VB app, but as more and more apps are placed on the server the additional install is less attractive. So I got to work on an XML based solution for both sending messages and retrieving directory information.


First things first, this sample uses the simplest of connectivity methods which is technically nothing more than an HTTP connection that sends XML instead of HTML. This sample uses Domino R6, but in R7 you can wrap this entire solution in the web service wrapper that R7 now has. The downside to the web service is if your calling application/platform does not have a SOAP client, you will have to build your own SOAP wrapper. For example, SOAP does not have native support in Javascript, so you are likely to use this type of method if you wanted to do an AJAX call. When I detail the method of retrieving directory information, we will meld the two methods into a single agent and use XML-RPC (the predecessor to SOAP) to make the calls.

The code is somewhat lengthy since I have alot of redundancies in place and I have not had a chance to optimize everything, but any corrections or ideas are welcome. This agent, and a sample form to call the method using AJAX, come in the Domino database at the bottom of this page.

First, I’ll profile what a typical XML call to this agent will look like. We’ll be referring to this example throughout the code walk. The database that comes with this code has a form called methodTest that will allow you to make an XML call to the agent, via AJAX, and return the results in a TEXTAREA.

<request>
  <auth_name>tester</auth_name>
  <auth_pass>(GDNrxflilfooyopmkjg)</auth_pass>
  <from>
    <value>Mail Tester</value>
  </from>
  <sendto>
    <value>PersonToReceive1</value>
    <value>PersonToReceive2</value>
  </sendto>
  <copyto />
  <blindcopyto />
  <subject>
    <value>test mail</value>
  </subject>
  <message_body>
    <value>testing mail send</value>
  </message_body>
  <attachments>
    <value>
      <file_name>globe.gif</file_name>
      <content_type>image/gif</content_type>
      <mime64>lOtSaMiMeJuNk</mime64>
    </value>
  </attachments>
</request>

Next, we’ll start off with our global variables. This method/agent is not setup to send multiple messages so many of our globals revolve around the outbound message.

Declarations:
Dim strOut As String        ' used as a catchall for error messages
Dim strMailSubject As String    ' our message subject line
Dim strMailBody As String    ' our body text for the message
Dim strFrom As String        ' the "from" address for our message
Dim bSuccess As Boolean        ' a flag to determine the return information
Dim arrParams(6) As String    ' a list of all out inbound parameters
Dim arrMailTo() As String    ' an array of names to send to
Dim arrCC() As String        ' an array of names to cc
Dim arrBcc() As String        ' an array of names to blind cc
Dim arrFileName() As String    ' an array of file names to attach
Dim arrContentType() As String    ' a matching array of the content types of the atts
Dim arrMime64() As String    ' an array of the mime encoded attachments

That’s pretty simple stuff, and so we move onto the Initialize event. For those of you that are LotusScript gods/goddesses, please be gentle with me ;) .

Pages: 1 2 3 4 5

One Response to “Send Notes mail from an XML call”

  1. nick wall Says:

    Hi there. Came across this article via codestore http://www.codestore.info/store.nsf/unid/BLOG-20060329, via Johan Känngård http://johankanngard.net/2005/12/13/sending-html-mails-via-lotusscript/ then you!

    We have a PC on our network, that is used to run an Excel program, the Excel file is then emailed to various users (they should really stick it in a central repository etc…). The sending user could log into their Web Access mail file, but as an interesting exercise, I would like to give this a go. I keep getting a 404 error when trying to download your sample database.

    Great site, interesting articles.

    Nick