Question : Mailmerge in Lotus from csv/AccessDB/Excel

Dear all

due to complete lack of programming skills in Lotus Notes... :-(

is it possible with a already developed tool or a small script to create Emails in LN R6.5 which are then stored in the drafts folder.

The input data looks like this:
+++++++++++++++++++
Record 1: UserA;Mister;500$
Record 2: UserB;Miss;200$
Record 3: UserC;Mister;800$
...
Record n:.....

It should then create n emails stored in the drafts folder in the folloing format:

-----------------------------
To: UserA
Subject: Costs: 500$
Body:

Dear UserA

it costs 500$

Thanks a lot
-----------------------------


Can anybody help? Your endeavours are greatly appreciated

Answer : Mailmerge in Lotus from csv/AccessDB/Excel

OK here is the procedure followed by the new script (replace the old script with this new one).  Let me know if there are any points which need further explaination (there probably will be if you're new to Notes!)

Cheers,
Steve


In the mail template as before:

Create a view called "CreateMailTemplate"
Edit the view, the column names dont really matter, but change the select criteria to:

SELECT Form = "CreateMailTemplate"

To change the select criteria, click anywhere on the white space in the middle of the screen whilst editing the view, and in the bottom left panel click on "View Selection".  In the bottom right pane where it says "Run" make sure "Formula" is selected.  In the white boc below this write the SELECT statement above.  Save the view.

I guess you know how to create a form as you have a table in one already:

Create a form called "CreateMailTemplate"
In the form write the word "Dear" followed by a space
Create a new field after the space (Create-Field).  Give it the name "USER"
Press Enter twice
Type "It costs" then a space and create another field, name it "COST"
Press Enter twice
Insert your table and format it as required
Below your table type "Thanks a lot"

Highlight your two fields and press Ctrl+B to make them bold.

Go to the menu item Design-Preview In Notes, save changes when asked.
In the preview select the menu item File-Save.
Press escape

Go to the view "CreateMailTemplate" in the Notes client

You should see one document there (the one you just saved) open it to make sure.  This is your template, if you ever want to change it - delete the document that is there now and go into your designer change it there and create a new document using the method above.  Make sure that the document always has the two fields USER & COST.

Note:  this template will also appear in your drafts folder - be careful not to delete it from there



START OF SCRIPT


Sub Initialize
      
      Dim LINE_DELIMETER As String
      Const FILENAME = "c:\temp\emails.txt"
      
      LINE_DELIMETER = Chr(13)+Chr(10)
      
      Dim fileNum As Integer
      Dim strLine As String
      
      
      fileNum = Freefile()
      Open FILENAME For Input As fileNum
      
      
      While strLine <> "-1"      
            If strLine <> "" Then
                  
                  MakeMail(strLine)      
                  
            End If
            strLine = GetNextLine(fileNum, LINE_DELIMETER)
      Wend
      
      
End Sub


Function GetNextLine(fileNum As Integer, lineDelimeter As String)  
      
      Dim strInput As String
      Dim char As String
      Dim testStr As String
      
      strInput = "-1"
      
      On Error Goto EndOf
      char = Input(1, fileNum)
      
      strInput = ""
      
      While testStr <> lineDelimeter
            
            strInput = strInput + char
            char = Input(1, fileNum)
            testStr = Right(testStr,1) + char
            
      Wend
      
ReturnString:
      GetNextLine = strInput
      Exit Function
      
EndOf:
      Resume ReturnString
      
      
      
End Function

Sub MakeMail(strLine As String)
      
      Dim strTo As String
      Dim strSubj As String
      Dim strBody As String
      
      Dim firstColon As Integer
      Dim firstSemi As Integer
      Dim secSemi As Integer
      Dim length As Integer
      
      Dim s As notessession
      Dim db As notesdatabase
      Dim doc As notesdocument
      
      ' ========================
      ' TEMPLATE MOD
      ' ========================      
      Const VIEW_NAME = "CreateMailTemplate"
      
      Dim tempView As notesview
      Dim tempDoc As notesdocument
      Dim rtiBody As notesrichtextitem
      
      ' ========================      
      
      
      
      firstColon = Instr(1, strLine, ":")
      firstSemi = Instr(1, strLine, ";")
      secSemi = Instr(firstSemi + 1, strLine, ";")
      length = Len(strLine)
      
      strTo = Mid(strLine, firstColon + 2, length - firstcolon - (length - firstSemi) - 2)
      strSubj = "Costs: " + Mid(strLine, secSemi + 1, length - secSemi )
      
      ' ========================
      ' TEMPLATE MOD
      ' ========================      
'      strBody = "Dear " + strTo + Chr(13) + Chr(13) + "It costs " + Mid(strLine, secSemi + 1, length - secSemi ) + _
'      Chr(13) + Chr(13) + "Thanks a lot."
      
      ' ========================            
      
      Set s = New notessession
      Set db = s.currentdatabase
      
      
      ' ========================
      ' TEMPLATE MOD
      ' ========================      
      
      Set tempView = db.getView(VIEW_NAME)
      Set tempDoc = tempView.getfirstdocument      
      
      Call tempDoc.replaceItemValue("USER", strTo)
      Call tempDoc.replaceItemValue("COST", Mid(strLine, secSemi + 1, length - secSemi ))
      tempDoc.save 1,1
      
      ' ========================
      
      Set doc = New notesdocument(db)
      
      Call doc.replaceitemvalue("Form", "Memo")
      Call doc.replaceitemvalue("SendTo", strTo)
      Call doc.replaceitemvalue("Subject", strSubj)
      
      ' ========================
      ' TEMPLATE MOD
      ' ========================      
'      Call doc.replaceitemvalue("Body", strBody)
      
      Set rtiBody = doc.CreateRichTextItem( "Body" )
      Call tempDoc.rendertoRTItem(rtiBody)
      ' ========================            
      Call doc.replaceitemvalue("PostedDate", "")
      Call doc.replaceitemvalue("$MessageType", "")
      
      
      doc.save 1, 1
      
      ' Drafts is a view in my version of Notes
'      Call doc.putinfolder("Drafts", True)      
      
      
      
End Sub



END OF SCRIPT
Random Solutions  
 
programming4us programming4us