這是一個學習關於如何使用Lotus Notes的Agent功能來實現自動化辦公的學習筆記。
一. 介紹
Lotus Notes/Domino 是一個世界領先的企業級通訊、協同工作及Internet/Intranet平台;具有完善的工作流控制、數據庫復制技術和完善可靠的安全機制;尤其適合於處理各種非結構化與半結構化的文檔數據、建立工作流應用、建立各類基於Web的應用。它全面實現了對非結構化信息的管理和共享,內含強大的電子郵件功能及工作流軟件開發環境,是實現群組協同工作、辦公自動化的最佳開發環境。
Notes的主要設計元素:
二. Lotus Notes 安裝和配置
2.1 Lotus 產品說明
IBM公司提供的這一軟件產品的全稱是IBM Lotus Notes & Domino. Notes是客戶端,Domino是服務器。
Lotus Notes是指Notes客戶端,它安裝在用戶個人電腦上,用於訪問電子郵件和Notes應用。
Domino則是Notes/Domino組合的服務器部分,它可以運行在各種操作系統中。當用戶通過Notes客戶端連接服務器備份郵件數據時,用來從用戶郵件數據庫中提取內容的正是Domino服務器。Domino服務器還負責控制郵件和應用數據庫的登錄和安全等。Domino服務器擁有強大的安全模式,可以控制訪問單個Notes文檔級別的安全性。主要通過基於用戶Notes ID登錄系統,以及數據庫和網絡通信加密技術等來實現。
2.2 安裝
2.2.1 環境:
服務器:DOMI_SRV_9.0_WIN_64_EN_TRIAL.exe
客戶端:NotDesg_9.0_WIN_SC_deve.exe/lotus_notes853_win_SC.exe
這里建議客戶端選擇Notes design。因為需要使用Domino Administrator來對Domino服務器進行配置,一般的Lotus Notes客戶端不附帶該組件。
2.2.2 Server安裝和配置:
服務器安裝步驟,安裝默認設置安裝服務器domino,服務器在初次啟動的時候,將要求配置該服務器。
詳細的配置方法可以參考后面的參考資料進行配置,這里只說明一些需要注意的地方:
1. 服務器名稱應與計算機名稱相同,否則在配置過程中可能會出現錯誤,導致服務器運行不正常或無法配置。計算機名稱的修改如下:右擊桌面的“我的電腦”,單擊“屬性”,選擇“計算機名”標簽,再單擊“更改”。
2. 自定義服務器管理員的用戶名和密碼,用戶只需要在“Last name”項中填入名稱即可。下面的“Also save a local copy of the ID file”要勾選,它會創建一個“admin.id”的文件,用戶加載到Note Administrator客戶端用於管理Domino服務器。
2.2.3 Client端的安裝和配置
1. 按照默認安裝完Notes后(如果不了解,可以參考后面的參考資料),連接上服務器。
如果想配置服務器的話,你需要安裝包含Administrator 的客戶端版本,這里安裝的是NotDesg_9.0_WIN_SC_deve.exe。
2. 配置郵件服務器
參考《IBM Lotus Domino 郵件服務器配置攻略》
三. Lotus Script語法介紹
LotusScript是一種和Basic相兼容的面向對象的Scripting環境,它具有強大的能夠從事面向對象應用軟件開發的語言范圍,能夠提供循環和分支的能力、數組以及訪問Notes對象的能力。
判斷Notes中什么時候使用LotusScript或公式語言
- 任何時候當執行該任務的函數或命令存在時,使用公式。
- 對於復雜的程序控制或循環,使用LotusScript。
- 存取或操作儲存的文檔數據要使用LotusScript,特別對於跨文檔、跨數據庫的存取。
- 若公式語言不能辦到,則使用LotusScript
具體內容請參考 《LotusScript語言的基本知識》
四. Lotus Notes 的Agent編程
在參考《在 Lotus Notes 中設置郵件定時發送的方法及代理功能介紹》中具體介紹了Agent的概念和如何使用。
這里只就Lotus Script的編程進行一些使用上的說明:
1. Declerations 用來定義一些函數或者全局變量,比如下面的 createPath 在Declerations中定義並實現后,將變成下面這樣
2. 程序的入口使用Initialize,Terminate入口一般不使用,如果程序實現在Terminate中,一些Lotus Script接口將無法被調用。
五. 具體實例
這里有一個Notes 的郵件附件處理Agent,具體的需求是根據郵件的時間和標題來創建文件夾,並將附件存儲在標題文件夾中。
1 Sub createPath(path As String) 2 3 Set objFSO = CreateObject("Scripting.FileSystemObject") 4 5 If objFSO.FolderExists(path) Then 6 'Messagebox ("Directory does exist") 7 Else 8 'Messagebox("Directory does not exist") 9 Mkdir (path) 10 End If 11 End Sub 12 13 14 15 16 17 Sub Initialize 18 19 Dim DirResult As String 20 Dim dirPath As String 21 dirPath = "d:\loans" 22 23 Dim names As String 24 Dim compname As String 25 Dim zhihangList(32) As String 26 zhihangList(0) = "scarlettduan" 27 zhihangList(1) = "jack" 28 zhihangList(2) = "god" 29 zhihangList(3) = "lu" 30 31 Dim session As New NotesSession 32 Dim db As NotesDatabase 33 Dim dc As NotesDocumentCollection 34 Dim doc As NotesDocument 35 Dim item As NotesItem 36 Dim body As NotesRichTextItem 37 Dim rtnav As NotesRichTextNavigator 38 Dim rtrange As NotesRichTextRange 39 40 Set db = session.CurrentDatabase 41 Set dc = db.UnprocessedDocuments 42 Set doc = dc.GetFirstDocument 43 Set body = doc.GetFirstItem("Body") 44 45 Set rtnav = body.CreateNavigator 46 47 REM 過濾發件人 48 Set item = doc.GetFirstItem("From") 49 If (item Is Nothing) Then 50 Msgbox "收件人不存在,這個程序不能運行 ",16,"退出" 51 Exit Sub '退出程序 1 52 Else 53 Dim nameArr 54 55 nameArr = Split(Cstr(item.Text),"/", -1, 1) 56 57 'For i = 0 To Ubound(nameArr) 58 ' Messagebox nameArr(i) 59 'Next i 60 61 '取倒數第三個作為發件人 62 'names = Mid(nameArr( Ubound(nameArr) - 2), 4) 63 names = Mid(nameArr(0), 4) 64 65 For i = 0 To Ubound(zhihangList) 66 If(zhihangList(i) = names) Then 67 'Messagebox ("find the zhihang from the list") 68 Goto Step1 69 End If 70 Next i 71 72 Msgbox "發件人不正確,可能不是你想要加工的郵件 ",16,"退出" 73 Exit Sub '退出程序 2 74 End If 75 76 77 Step1: 78 79 REM 過濾附件信息 80 If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then 81 82 Dim filetype As String 83 Do 84 Set att = rtnav.GetElement() 85 filetype = Strright(att.Source,".") 86 'Messagebox filetype 87 If filetype = "xls" Or filetype = "xlsx" Then 88 Msgbox "該郵件中存在EXCEL 附件,可能不是你想要加工的郵件 ",16,"退出" 89 Exit Sub '退出程序 3 90 End If 91 92 Loop While rtnav.FindNextElement() 93 Else 94 Msgbox "該郵件中不存在附件,可能不是你想要加工的郵件 ",16,"退出" 95 Exit Sub '退出程序 5 96 End If 97 98 99 REM 獲得時間,創建文件夾 100 Dim timeArr 101 Dim myMouth As String 102 Dim myDay As String 103 Dim dateTime As New NotesDateTime( "" ) 104 Set item = doc.GetFirstItem( "DateComposed" ) 105 106 dateTime.LSLocalTime = doc.Created 107 108 createPath(dirPath) 109 110 myMouth = Format(Cstr(dateTime.LSLocalTime), "yyyymm") 111 dirPath = dirPath & "\" & myMouth 112 113 'Messagebox "dirPath " & dirPath 114 createPath(dirPath) 115 116 myDay = Format(Cstr(dateTime.LSLocalTime), "yyyymmdd") 117 dirPath = dirPath & "\" & myDay 118 119 'Messagebox "dirPath " & dirPath 120 createPath(dirPath) 121 122 123 REM 這里需要根據實際情況修改 124 REM 獲得郵件標題,創建文件夾 125 Set item = doc.GetFirstItem( "Subject" ) 126 127 128 If ( item.Text = "" ) Then '如果該郵件沒有標題,根據需要創建文件名 129 130 'Messagebox( "There is no Subject item on the document.you need to create file by youself" ) 131 compname = Cstr(Inputbox$("There is no Subject item on the document. " + Chr(13) + "the document name should be?")) 132 133 If(compname = "") Then 134 Msgbox "你必須輸入一個公司名稱 ",16,"退出" 135 Exit Sub '退出程序 4 136 End If 137 138 compname = dirpath & "\" & names & compname 139 createPath(compname) 140 141 Else ' 在郵件有標題的情況下 142 143 'Messagebox( "The Subject item on the document has the value: " + item.Text ) 144 Dim subArr 145 Dim haveComp As Boolean 146 'Dim names As String 147 148 haveComp = False 149 subArr = Split(Cstr(item.Text),":", -1, 1) 150 151 'Messagebox subArr(0) & " " & Cstr(item.Text) 152 '一般情況下,格式為xxx申請:xxx公司,這里表示沒有使用“:”作為分隔符的情況下,提示手動輸入 153 If subArr(0) = item.Text Then '如果非上面格式的情況,使用“:”分割的郵件名 154 155 'Messagebox ("have not 公司 1") 156 compname = Cstr(Inputbox$("There is no Subject item on the document. " + Chr(13) + "the document name should be?")) 157 158 If(compname = "") Then 159 Msgbox "你必須輸入一個公司名稱 ",16,"退出" 160 Exit Sub '退出程序 4 161 End If 162 163 compname = dirpath & "\" & names & compname 164 createPath(compname) 165 166 Else 167 For i = 0 To Ubound(subArr) 168 169 '這里是創建文件夾的關鍵位置,公司名需要是帶有申請兩字的后面 170 If Instr(subArr(i), "申請") = 0 Then '''''''(1) 171 '如果整個標題中都沒有上面的關鍵字,該處理將在后面進行,對於下面的have not 公司 2 172 Else 173 'Messagebox ("hava 公司 2") 174 haveComp = True 175 compname = subArr(i + 1) 176 compname = dirpath & "\"& names & compname 177 createPath(compname) 178 End If 179 Next i 180 181 '一般情況下,下面的路徑不會運行到 182 If haveComp = False Then 'have not 公司 2.對於上面的(1) 183 184 'Messagebox ("have not 公司 2") 185 compname = Cstr(Inputbox$("There is no Subject item on the document. " + Chr(13) + "the document name should be?")) 186 187 If(compname = "") Then 188 Msgbox "你必須輸入一個公司名稱 ",16,"退出" 189 Exit Sub '退出程序 4 190 End If 191 192 compname = dirpath & "\" & names & compname 193 createPath(compname) 194 End If 195 End If 196 197 End If 198 199 200 REM Get attachments 201 If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then 202 203 Do 204 Set att = rtnav.GetElement() 205 filepath$ = compname + "\" & att.Source 206 207 'Messagebox(filepath$) 208 Call att.ExtractFile(filepath$) 209 'Print filepath$ & " extracted" 210 Loop While rtnav.FindNextElement() 211 212 End If 213 End Sub
參考資料:
IBM Lotus Domino Server首次配置詳解 http://net.zol.com.cn/103/1032259.html
IBM Lotus Domino 郵件服務器配置攻略 http://net.zol.com.cn/105/1052918.html
LotusScript基本語法及舉例分析 http://news.ccidnet.com/art/32855/20100709/2110929_1.html
LotusScript語言的基本知識 http://wnight88.blog.51cto.com/512204/140459
在 Lotus Notes 中設置郵件定時發送的方法及代理功能介紹 http://www.ibm.com/developerworks/cn/lotus/notes-timing/