如何使用LotusScript代理來發送HTML格式的郵件

來源:互聯網
上載者:User

產品: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.