Search

Tuesday, March 27, 2007

Auto reply email script - LotusScript

Today I had to write a script to run in a Lotus Notes database that generates an auto reply email when a form is submitted. The email is sent to the email address specified in the "Email" field on the form. This script is relatively simple, written in LotusScript and works a treat. One tricky thing that I had to work out was to be able to send the email from a specific email address, as setting "From" field did not work. When the email hit the Domino server its value was set Anonymous. This causes problems as allot of spam filters reject the email, including Google's, which was what I was originally testing with. I have commented out the "ReplyTo" as even without this set, when you click reply in your Inbox the email still replies to info@munchtechnologies.com.au. If someone out there knows why this is I would be interested.

Sub Initialize

Dim Session As New NotesSession
Dim DocWeb As NotesDocument
Dim DBCur As NotesDatabase
Dim tmpEmail As String
Dim EmailTo As String
Dim rtitem As NotesRichTextItem

Set DBCur = Session.CurrentDatabase
Set DocWeb = Session.DocumentContext

tmpEmail = DocWeb.GetFirstItem("Email").Text

Set WorkApps = New NotesDocument(DBCur)
Set rtitem = New NotesRichTextItem( WorkApps , "Body")

WorkApps.SendTo = tmpEmail
WorkApps.Principal = "info@munchtechnologies.com.au"
WorkApps.INetFrom = "info@munchtechnologies.com.au"
WorkApps.DisplaySent = "info@munchtechnologies.com.au"
'WorkApps.ReplyTo = "info@munchtechnologies.com.au"
'WorkApps.From = "info@munchtechnologies.com.au"
WorkApps.Form = "Memo"
WorkApps.Subject = "Job Application Received - Munch Technologies"

Call rtitem.appendtext("This email is to let you know that we have received your job application.")
Call rtitem.AddNewline(2)
Call rtitem.appendtext("If you are required for an interview, a member of the Munch Technologies Management Team will contact you directly.")
Call rtitem.AddNewline(2)
Call rtitem.appendtext("Thank you for taking the time to complete the application form. Your application will be kept on file for 3 months.")
Call rtitem.AddNewline(2)
Call rtitem.appendtext("For any further information please contact us directly through the contact us section at http://www.munchtechnologies.com.au")
Call rtitem.AddNewline(2)

WorkApps.send True

End Sub


Hope you Lotus Notes heads out there find this useful.