CSDN博客

img chenyg2000

How to store raw MIME message to notes database

发表于2004/10/11 16:08:00  920人阅读

转自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

阅读全文
0 0

相关文章推荐

img
取 消
img