How to store raw MIME message to notes database

博客指出不要在邮件应用中使用示例代码,Notes和Domino可自动发送HTML邮件,仅在数据库存储原始MIME数据时需代码。介绍了Notes 6中可用LotusScript的NotesMIMEEntity类创建MIME Part项,而R5中该类只读,需用API调用实现相同功能。

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

转自ldd(http://www-10.lotus.com/ldd/46dom.nsf/c21908baf7e06eb085256a39006eae9f/8a656aebb3d4932a80256b90003bba52?OpenDocument)
Note:
Do not use this sample code in e-mail applications! Notes and Domino can send HTML e-mail automatically from Notes Rich Text. You do not need to write any code at all to send HTML e-mails. You only need this code to store raw MIME data in a database.

This is implemented in Notes 6, where you can use the NotesMIMEEntity class in LotusScript to create MIME Part items. For example, here is code in a button that sends an HTML e-mail.


Sub Click(Source As Button)
sendto$ = "myself@someisp.com"
subject$
= "Notes 6 MIME"
htmltext$
= {<font size=2 face="sans serif">This is an <b>HTML</b> message.</font>}

Dim session As New NotesSession

Dim html As NotesStream
Set html = session.CreateStream
html.WriteText htmltext$

Dim doc As New NotesDocument(session.CurrentDatabase)

Dim
mime As NotesMIMEEntity
Set mime = doc.CreateMIMEEntity("Body")
mime.SetContentFromText html, "text/html", ENC_NONE

doc.Subject
= subject$
doc.Send
False, sendto$
End Sub


In R5 the NotesMIMEEntity class is read-only. You can use it to read an existing MIME Part item, but not to create a new MIME Part item. So, in R5, you have to use API calls to do the same thing:


Const wAPIModule = "NNOTES" ' Windows/32
Const TYPE_MIME_PART = 25

Type MIMEPart
Version
As Integer
Flags0 As Integer
Flags1 As Integer
Type As Integer
Size As Integer
BoundaryLength As Integer
HeadersLength As Integer
Spare0 As Integer
Spare1 As Long
Text(1023) As Long
End Type

Declare Private Function
NSFDbOpen Lib wAPIModule Alias "NSFDbOpen" _
( Byval P As String, hDB As Long) As Integer
Declare Private Function
NSFDbClose Lib wAPIModule Alias "NSFDbClose" _
( Byval hDB As Long) As Integer

Declare Private Function
NSFNoteOpen Lib wAPIModule Alias "NSFNoteOpen" _
( Byval hDB As Long, Byval NoteID As Long, Byval F As Integer, hNT As Long) As Integer
Declare Private Function
NSFNoteClose Lib wAPIModule Alias "NSFNoteClose" _
( Byval hNT As Long) As Integer
Declare Private Function
NSFNoteUpdate Lib wAPIModule Alias "NSFNoteUpdate" _
( Byval hNT As Long, Byval F As Integer) As Integer

Declare Private Function
NSFItemAppend Lib wAPIModule Alias "NSFItemAppend" _
( Byval hNT As Long, Byval F As Integer, Byval N As String, Byval nN As Integer _
, Byval T As Integer, V As Any, Byval nV As Long) As Integer

Declare Private Function
OSPathNetConstruct Lib wAPIModule Alias "OSPathNetConstruct" _
( Byval zP As Long, Byval S As String, Byval F As String, Byval N As String) As Integer

Declare Private Sub
PokeLSString Lib "MSVCRT" Alias "memcpy" _
( D As Long, Byval S As String, Byval N As Long)

Sub
Click(Source As Button)
sendto$ = "myself@someisp.com"
subject$
= "Notes R5 MIME"
htmltext$
= {<font size=2 face="sans serif">This is an <b>HTML</b> message.</font>}

crlf$ = Chr$(13) & Chr$(10)
header$ = "Content-Type: text/html" & crlf$ & crlf$
bodyitem$
= "Body"

Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase

Dim doc As New NotesDocument(session.CurrentDatabase)
doc.Subject = subject$
doc.Save
True, False
id$ = doc.NoteID
Delete doc

np$
= Space(1024)
OSPathNetConstruct 0, db.Server, db.FilePath, np$

Dim hDB As Long
NSFDbOpen np$, hDB

Dim hNT As Long
NSFNoteOpen hDB, Clng("&H" & id$), 0, hNT

Dim body As MIMEPart
body.Version
= 2
body.Flags0
= 2 ' has headers
body.Type = 2 ' body
body.Size = Len(header$) + Len(htmltext$)
body.HeadersLength = Len(header$)
PokeLSString body.Text(0), header$ & htmltext$, Clng(body.Size)

NSFItemAppend hNT
, 0, bodyitem$, Len(bodyitem$), TYPE_MIME_PART, body.Version, Clng(body.Size + 20)
NSFNoteUpdate hNT
, 0

NSFNoteClose hNT
NSFDbClose hDB

Set doc = db.GetDocumentByID(id$)
doc.Send False, sendto$
doc.Remove
True
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值