Sending an email from lotuscript agent (not using Domino smtp server)

Why would you want to ? Well if the server that hosts your notes domino services also happens to be running an SMTP server such as Mercury or Exchange instead of the Domino variant. You might want to generate an email as the result of an agent running – as in this example where I want the agent to run through a collection of records in a view and then collate an email which gets sent to a distribution list. The server in question is a Windows 2003 Web edition. Take the time to read through the sample code – it should be fairly self explanatory..

So what do you need ?

1) Well first a utility called smtpsend from Dataenter – download and save in c:smtpsend folder as used in this example – you’ll get it here

2) create an agent that will generate the file you wish to send as the body of the email. Add some code like the following for your application to generate a file containing the info you want. I attach my code to the initialise property of the agent (remember to sign and schedule it).

Here comes the science bit ……

Sub Initialize

Dim crlf As String
Dim cr As String
Dim lf As String

cr$=Chr(13) ‘ Carriage return
lf$=Chr(10) ‘ line feed
crlf$=Chr(13) & Chr(10) ‘ Carriage return/line feed

Dim sess As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc1 As NotesDocument
Dim doc2 As NotesDocument

REM counters
Dim totalissues As Integer

REM Initialise counters

totalopenissues = 0

REM File Handling

Dim filenum As Integer
Dim pos As Integer
Dim strOutput As String
‘Text filename to write the output to. Writes to Notes program directory.
filename = “issues.txt”
filenum = Freefile()
Open filename For Output As fileNum
Print #filenum, “[ Helpdesk Issues Report]”
Print #filenum, “========================”
Print #filenum, crlf

Dim lstime As Variant

Dim longstr As String
Set db = sess.CurrentDatabase
Set view = db.GetView(“Issues”)
Set doc1 = view.GetFirstDocument
While Not (doc1 Is Nothing)
If Not (doc1 Is Nothing) Then

issuedate = doc1.created
issuecust = doc1.GetItemValue(“NAMEOFCUSTOMER”)(0)
issuedesc = doc1.GetItemValue(“issuedescription”)(0)
issueurg = doc1.GetItemValue(“issueurg”)(0)

REM Get the rest of the fields and build long string
longstr = longstr + ” ” + Cstr(issuedate) + ” : > ” + issuecust + ” < - " + issuedesc + " - [ " + issueurg + " ]" + crlf + crlf Set doc2 = view.GetNextDocument(doc1) Set doc1 = doc2 End If totalopenissues = totalopenissues + 1 Wend REM set up output Dim totstr As String *30 totstr = "Total Open Issues" Print #filenum, totstr + " : " + Cstr(totalopenissues) Print #filenum, crlf Print #filenum, " [ Issue Summary ]" Print #filenum, "=================== " Print #filenum, longstr Close filenum result = Shell( "C:smtpsendsmtpsend.exe -fauthoriseduser@domainhostedthroughsmtpserver -iissues.txt -hipaddressofsmtpserverthatwillsend -luAuthorisedSmtpusername -lpAuthorisedpassword -SIssue Summary" ,1) End Sub I will need to explain the key section in more detail since this is the section that takes the file your agent created and sends it as an email – but first the details of smtpsends command line options !!

SMTPSend uses the following switches:


Senders address
Recipients address
CC address
BCC address
-h Send message to host
-p Port (default is port 25)
-s Subject of the message
-a File(s) to attach to the message (wildcards allowed)
-i File(s) to import into message body (wildcards allowed)
-1 Enable Single-To mode
-v Verbose mode (show message transfer)
-g Send a raw RFC 821/822 file (ignores -c,-a,-i,-s,-r)
-lu SMTP authentication user
-lp SMTP authentication password
-lCA TLS CA-Certificate PEM file
S/MIME sign certificate PEM file
S/MIME encrypt certificate PEM file
-n Force normal SMTP (do not use ESMTP)
-dNFSD DSN Never, Failure, Success, Delay
-os SMTP options
-mfH Message format HTML
-mhL Message header line
-mRR Enable Read Receipt
-@ Read additional arguments from a file (-@FILE.EXT)


So in the code above – I’ve replaced some of the values really used with the ones you need to change – so some clarification of this key part of the agent sending the email.

result = Shell( “C:smtpsendsmtpsend.exe -fauthoriseduser@domainhostedthroughsmtpserver -iissues.txt -hipaddressofsmtpserverthatwillsend -luAuthorisedSmtpusername -lpAuthorisedpassword -SIssue Summary” ,1)

So that the action is to shell to dos – run the smtpsend command – and then return the result into the result variable

NOTE THE double required

authoriseduser@domainhostedthroughsmtpserver – is a real email address on your chosen smtp server – the individual or group of people you want to send the email to

AuthorisedSmtpusername – if using smtp auth – use a username you have allowed to send mail

Authorisedpassword – the password for that authorised account

You can test the smtpsend utility from a dos prompt on the Notes server to make sure that you have the correct parameters before trying to debug it on the notes server. The agent then needs to be scheduled and run from the server. Monitor the notes console for a message from SMTPSEND or an error from your code!!