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