產品:Lotus Domino
平台:AIX, HP-UX, i5/OS, Linux, Solaris, Windows, z/OS
軟體版本:6.0, 6.5
問題描述:
如何使用LotusScript來發送HTML格式的郵件訊息?
在拓展Lotus Notes中NotesMIMEEntity類和Lotus Domino Desitner 6.x版本之前,使用調度的代理來發送HTML格式的郵件是不太可能的。當你把HTML代碼加入到郵件主體中,即使設定了PassThruHTML NotesRichTextStyle屬性,Notes仍然會把郵件作為原始的HTML代碼發送。
解答:
NotesMIMEEntity類中的新方法和新屬性,以及NotesStream類,使得在Notes/Domino 6.x版本中用調度的代理髮送HTML格式的郵件成為可能。這功能對於寄送HTML通訊或者作為給郵件資料庫提交資訊使用者的回複有用。你可以建立一代理程式,發送儲存在本地檔案系統上的HTML或動態建立HTML。下面的代理舉例說明了上述功能。
重要注釋:下列的是例子指令碼,僅以提供一種處理這種問題的方式,為了這樣本示範正常,指令碼必須要和例子一致。IBM支援人員不能為客戶訂製該指令碼
使用本地HTML檔案
下面的代理從本地檔案系統(伺服器的硬碟)發送HTML檔案:
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream
Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False ' Do not convert MIME to rich text
Set doc = db.CreateDocument
doc.Form = "Memo"
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal("HTML message") ' this is the subject
Set header = body.CreateHeader("To")
Call header.SetHeaderVal("user@us.ibm.com") ' this can be a list of users separated by commas
'The file named below is located on the Domino server because the scheduled agent runs on the Domino server
Call stream.Open("c:\newsletter.html")
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call doc.Send(False)
s.ConvertMIME = True ' Restore conversion
使用動態HTML內容
下面的代理動態產生HTML檔案。可以給HTML檔案加入動態內容。
注意stream.WriteText方法使用管道( | )字元作為分隔字元而不是引號。這種用法就可以把引號直接放在字串前面。同時WriteText線是分離的,易於使用者閱讀。不過如果需要它們也能被串連在一起。
範例程式碼包括EOL_CRLF字元使得訊息原始碼恰當的格式化。這一點很重要因為很多垃圾過濾器會過濾掉格式有誤的MIME資訊
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream
Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False ' Do not convert MIME to rich text
Set doc = db.CreateDocument
doc.Form = "Memo"
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal("HTML message")
Set header = body.CreateHeader("To")
Call header.SetHeaderVal("user@us.ibm.com")
Call stream.writetext(|<HTML>|)
Call stream.writetext(|<body bgcolor="blue" text="white">|)
Call stream.writetext(|<table border="2">|)
Call stream.writetext(|<tr>|)
Call stream.writetext(|<td>Hello World!</td>|)
Call stream.writetext(|</tr>|)
Call stream.writetext(|</table>|)
user$ = s.CommonUserName 'if scheduled agent this returns the name of the server
'Below uses the ampersand (&) to concatenate user$
Call stream.writetext(|<br><font size="+5" color="red">| & user$ &|</font>|)
Call stream.writetext(|</body>|)
Call stream.writetext(|</html>|)
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call doc.Send(False)
s.ConvertMIME = True ' Restore conversion - very important