现在的位置: 首页 > 综合 > 正文

源码:使用LotusScript发送mime格式邮件

2011年09月24日 ⁄ 综合 ⁄ 共 2704字 ⁄ 字号 评论关闭

群友们经常问此类问题,收集下,供参考

01Sub Initialize()
02 '定义变量
03 Dim s As New NotesSession
04 Dim db As NotesDatabase
05 Dim body As NotesMIMEEntity, bodyChild As NotesMIMEEntity
06 Dim header As NotesMIMEHeader
07 Dim stream As NotesStream
08 Dim host As String
09 Dim message As NotesDocument
10 Set db = s.CurrentDatabase
11 s.ConvertMIME = False  
12 ' Do not convert MIME to rich text  Set stream = s.CreateStream
13 Set message = db.CreateDocument
14 message.Form = "Memo"
15 
16 Set body = message.CreateMIMEEntity
17 message.Subject = "通过MIME格式发送邮件"
18 message.SendTo = "squallzhong@gmail.com<SCRIPT type=text/javascript>
19/* <![CDATA[ */
20(function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
21/* ]]> */
22</SCRIPT>"  
23 
24 Set stream = s.CreateStream()
25 ' 设置HTML标题
26 Call stream.WriteText ("<html><head><title>通过MIME格式发送邮件</title>")
27 ' BEGIN: 设置CSS
28 Call stream.WriteText (|
29 <style type="text/css">
30 <!--
31 .text, td, tr, p, br, body {
32 COLOR: #666666;
33 FONT-FAMILY: Arial, Helvetica, sans-serif;
34 FONT-SIZE: 12px;
35 }
36 a {
37 font-family: Arial, Helvetica, sans-serif;
38 color: #663399;
39 FONT-WEIGHT: bold;
40 text-decoration: none;
41 }
42 -->
43 </style>
44 |)
45 '--------------------------------------------
46 Call stream.WriteText ({</head>})
47 ' BEGIN: 设置主体信息
48 Call stream.WriteText ({<body text="#666666" bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">})
49 Call stream.WriteText ({ <table width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF"><tr><td>测试MIME邮件-主体表格</td></tr></table>)
50 Call Stream.WriteText({测试MIME邮件-主体文字})
51 Call stream.WriteText({</body></html>})
52 
53 '将stream中的主体信息内容放置在一个子mime单元中
54 Set bodyChild = body.CreateChildEntity()
55 Call bodyChild.SetContentFromText (stream, "text/html;charset=utf-8", ENC_NONE)  
56 Call stream.Close
57 Call stream.Truncate
58 '--------------------------------------------
59 
60 '附件单元
61 Set bodyChild = body.CreateChildEntity()
62 Set header = bodyChild.createHeader("Content-Type")
63 Call header.setHeaderVal("multipart/mixed")
64 
65 Set header = bodyChild.createHeader("Content-Disposition")
66 Call header.setHeaderVal("attachment; filename=文档.doc")  
67 
68 Set header = bodyChild.createHeader("Content-ID")
69 Call header.setHeaderVal("文档.doc")  
70 
71 Set stream = s.CreateStream()
72 If Not stream.Open("c:\temp\文档.doc", _
73 "binary") Then
74  Print "打开文伯失败"
75 End If
76 If stream.Bytes = 0 Then
77  Print "文件中不包含内容"
78 End If
79 Call bodyChild.SetContentFromBytes(stream, "application/msword", ENC_IDENTITY_BINARY)
80 %REM
81  application/msword 文档匹配的content-type
82  如:image/gif application/msword application/pdf application/zip
83 %END REM
84 
85 '发送
86 Call message.Send (False)  
87 s.ConvertMIME = True
88End Sub

抱歉!评论已关闭.