如何使用 LotusScript 代理来发送 HTML 格式的邮件

本文介绍如何使用LotusScript在Notes和DominoDesigner6.x及以上版本中发送HTML格式的邮件,提供了两种方法:一种是从本地文件系统发送HTML文件;另一种是动态生成HTML内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Technote (troubleshooting)


问题

如何使用 LotusScript 来发送 HTML 格式的邮件消息?

在 Notes 和 Domino Designer 6.x及以上版本中拓展了 NotesMIMEEntity 类,此前使用定时代理来发送 HTML 格式的邮件是不太可能的。当你把 HTML 代码加入到邮件主体中,即使设置了 NotesRichTextStyle 属性为 PassThruHTML,Notes仍然会把邮件作为原始的 HTML 代码发送。


解决问题

Domino 6 以上版本中 NotesMIMEEntity 类的方法和属性,以及新增的 NotesStream 类,使得通过定时代理发送 HTML 格式的邮件成为可能。这对于寄送 HTML 新闻邮件或者给邮件数据库提交信息的用户自动回复很有帮助。你可以创建一个代理程序,发送存储在本地文件系统上的 HTML 或动态创建 HTML。下面的代理举例说明了上述功能。

重要注释:以下代码只是一个样例,证实了实现这项功能的一种方法,如需使用则用户自己承担相应的风险。为了保证该样例能够正常工作,必须严格按照上面的写法去执行,产品支持部门不支持对该代码的定制。

Hide details for 使用本地 HTML 文件使用本地 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("SendTo")
Call header.SetHeaderVal("user@us.ibm.com")
'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



Hide details for 使用动态HTML内容使用动态HTML内容

下面的代理动态的生成HTML文件。可以给HTML文件加入动态内容。

注意stream.WriteText方法使用管道( | )字符作为分隔符而不是引号。这种用法就可以把引号直接放在字符串前面。同时WriteText与线是分离的,易于用户阅读。不过如果需要它们也能被连接在一起。

示例代码包括换行符,使得消息的源代码具有正确的格式。这一点很重要,因为很多防垃圾邮件系统会过滤掉格式有误的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

Hide details for 提示主题,姓名和HTML文件提示主题,姓名和HTML文件


Sub Initialize
Dim uiwk As New NotesUIWorkspace
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
Dim vname As Variant
Dim vfile As Variant
Dim ssubject As String
Dim snames As String
Dim sfile As String

ssubject = CStr(InputBox("Please enter a subject","Subject input dialog"))
vname = uiwk.PickListStrings(PICKLIST_NAMES,True)
vfile = uiwk.OpenFileDialog(False,"Please select the HTML file to import")
ForAll names In vname
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 stream.Open(vfile(0))
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call header.SetHeaderVal(subject) ' this is the subject
Set header = body.CreateHeader("SendTo") 'alternatively you can use "BlindCopyTo" instead of "SendTo"
Call header.SetHeaderVal(names)
Call doc.Send(False)
s.ConvertMIME = True ' Restore conversion
End ForAll
End Sub

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值