最近想做一个通过Louts发送邮件的小东西,从网上找了半天,什么微软的OutLook Connector, IBM的Domino Access for Microsoft Outlook,都太烦琐。今天发现一个VB的COM方法,改成VFP的。我的邮件数据库是在远程服务器上,按照原文无法打开邮件数据库,只得改成bookmark.nsf,现在测试发送是成功。有需要的自行再测试吧。
* 函数功能:发送带附件的邮件给recipient变量中指定的收件人
* 运行环境:安装并配置好Notes客户端,并且已经登录到Notes,已经测试Notes 5和Notes 7
* SendMail(cSubject As String, cAttachment As String, cRecipient As String, cCopyToRec AS String, cBodyText)
* 执行成功返回.T.,失败返回.F.
* SendMail("我的测试邮件标题","d:\testfile.txt","zhj/sd/ccb","","我的测试邮件内容") &&附件为d:\testfile.txt
PARAMETERS cSubject As String, cAttachment As String, cRecipient As String, cCopyToRec AS String, cBodyText As String
* 设置对象属性
LOCAL oMaildb As Object, oMailDoc As Object, oAttachME As Object, oSession As Object,oEmbedObj As Object, lIsRight As Logical
lIsRight = .T.
TRY
oSession = CREATEOBJECT("Notes.NotesSession") &&创建Notes会话
oMaildb=oSession.GetDatabase("","bookmark.nsf") &&打开一个数据库
IF oMaildb.ISOPEN = .F. &&判断已经打开
oMaildb.OPENMAIL()
ENDIF
* 创建新邮件
oMailDoc = oMaildb.CREATEDOCUMENT()
oMailDoc.Form = "Memo"
oMailDoc.sendto = cRecipient &&收件人
oMailDoc.copyto = cCopyToRec &&抄送
oMailDoc.Subject = cSubject &&邮件标题
oMailDoc.Body = cBodyText &&邮件内容
oMailDoc.PostedDate=DTOC(DATE()) &&发送日期
* 添加附件
IF NOT EMPTY(cAttachment)
oAttachME = oMailDoc.CREATERICHTEXTITEM("cAttachment")
oEmbedObj = oAttachME.EmbedObject(1454, "", cAttachment, "attachment")
ENDIF
* 发送文档
oMailDoc.SEND(0)
CATCH
lIsRight = .F.
ENDTRY
RELEASE oMaildb, oMailDoc, oAttachME, oSession, oEmbedObj
RETURN lIsRight