Tip

Detailed E-Mail Agent

Have you ever wanted to send a mail message to notify users when a document has
been created or modified? Of course you can use the Send Mail basic action or
the @MailSend function, however both are limited in what you can do with the
message. One limitation is the ability to change text attributes (like color,
font size, etc.).

The example below will do the following:

1. Look for unprocessed documents
2. Read in several fields from the unprocessed documents.
3. Create an e-mail message with field labels and data as listed on the
documents using different colors.
4. If special conditions exist with the requested and/or servers field, a new
paragraph is added.
5. A doc-link is attached and the document is e-mailed.

Note - this process was created for use with an online request form for
catering services.

Enjoy!
jv
REM Establish Elements
Dim db As NotesDatabase
Dim session As New NotesSession
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim richstyle As NotesRichTextStyle

REM Set Environment
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments

REM Established Loop For Mail Agent
For i=1 To Collection.Count

Set doc = Collection.GetNthDocument(i)

REM Set variable values
DateofFunction$=doc.DateofFunction(0)
NumberofGuests$=doc.NumberofGuests(0)
Location$=doc.Location(0)
FunctionTime$=doc.Time(0)
ChargeToName$=doc.ChargeToName(0)
ChargeToAcct$=doc.ChargeToAcct(0)
Requested$=doc.Requested(0)
Servers$=doc.Servers(0)

REM Set Environment for e-mail messsage.
Set maildoc = New NotesDocument(db)
Set richstyle = session.CreateRichTextStyle
Set rtitem = New NotesRichTextItem(maildoc,"Body")

REM Create message, as described below:

REM Write original line in black text:
Call rtitem.AppendText("The following request has been submitted
online:")

REM Skip two lines and tab indent.
Call rtitem.AddNewLine( 2 )
Call rtitem.AddTab( 1 )

REM Write labels in black, the data in dark magenta.
Call rtitem.AppendText("Date of Function: ")
richstyle.NotesColor = COLOR_DARK_BLUE
Call rtitem.AppendStyle(richstyle)
Call rtitem.AppendText(Cstr(DateofFunction$))

REM Skip one line, tab indent and change color to black.
Call rtitem.AddNewLine( 1 )
Call rtitem.AddTab( 1 )
richstyle.NotesColor = COLOR_BLACK
Call rtitem.AppendStyle(richstyle)

Call rtitem.AppendText("Number of Guests: ")
richstyle.NotesColor = COLOR_DARK_BLUE
Call rtitem.AppendStyle(richstyle)
Call rtitem.AppendText(Cstr(NumberofGuests$))

REM Skip one line, tab indent and change color to black.
Call rtitem.AddNewLine( 1 )
Call rtitem.AddTab( 1 )
richstyle.NotesColor = COLOR_BLACK
Call rtitem.AppendStyle(richstyle)

Call rtitem.AppendText("Location: ")
richstyle.NotesColor = COLOR_DARK_BLUE
Call rtitem.AppendStyle(richstyle)
Call rtitem.AppendText(Cstr(Location$))

REM Skip one line, tab indent and change color to black.
Call rtitem.AddNewLine( 1 )
Call rtitem.AddTab( 1 )
richstyle.NotesColor = COLOR_BLACK
Call rtitem.AppendStyle(richstyle)

Call rtitem.AppendText("Function Time: ")
richstyle.NotesColor = COLOR_DARK_BLUE
Call rtitem.AppendStyle(richstyle)
Call rtitem.AppendText(Cstr(FunctionTime$))

REM Skip one line, tab indent and change color to black.
Call rtitem.AddNewLine( 1 )
Call rtitem.AddTab( 1 )
richstyle.NotesColor = COLOR_BLACK
Call rtitem.AppendStyle(richstyle)

Call rtitem.AppendText("Charge To (Name/Account): ")
richstyle.NotesColor = COLOR_DARK_BLUE
Call rtitem.AppendStyle(richstyle)
Call rtitem.AppendText(Cstr(ChargeToName$)+"/")
Call rtitem.AppendText(Cstr(ChargeToAcct$))

REM Change color to black.
richstyle.NotesColor = COLOR_BLACK
Call rtitem.AppendStyle(richstyle)
Call rtitem.AddNewLine( 2 )

REM Check for special conditions in the request.
If Requested$="Yes" Or Servers$="Yes" Then
Call rtitem.AppendText(

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.