mapi与cdo

来源:互联网 发布:莫知我哀句式 编辑:程序博客网 时间:2024/06/05 00:51

因为要用到消息编程,于是考察了一下mapi和CDO
刚开始图简单,使用了MAPI  ActiveX Control来编程,mapi ActiveX control有两个类(我使用的c++编程),CMAPISession和CMAPIMessage,使用起来非常简单。但底层还是用如Outlook Express之类的发送邮件,有时出现Outlook Expresss的发送邮件对话框,十分不爽。
于是开始搜寻MAPI的底层编程,mapi底层功能很强大,说是COM组件,但我看microsoft的例子中还是使用LoadLibrary装入msmapi32.dll,调用的还是普通的dll函数,似乎没看见COM的影子。在mapi之上有simple mapi, command messaging call和cdo。cdo是面向对象的com组件,比mapi底层使用要方便一些,于是选定cdo.
cdo也有很多版本,最开始叫ole messaging,然后是active messaging,现在叫cdo。有在Windows NT上用的cdonts.dll,for Windows 2000的cdosys.dll,for Exchange的cdoex.dll,还有管理、工作流的cdo。
先考察一下cdosys.dll,写了个vb的邮件发送程序:
Sub czm()
Dim iMsg As New CDO.Message
Dim iConf As New CDO.Configuration

Dim Flds As ADODB.Fields
Set Flds = iConf.Fields

With Flds
  .Item(cdoSendUsingMethod) = cdoSendUsingPort
  .Item(cdoSMTPServer) = "pop.tom.com"
  .Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
  .Item(cdoSMTPAuthenticate) = cdoBasic

  ' IMPORTANT: Storing user names and passwords inside source code
  ' can lead to security vulnerabilities in your software. Do not
  ' store user names and passwords in your production code.
  .Item(cdoSendUserName) = "zeki"
  .Item(cdoSendPassword) = "zeki"

  .Update
End With

With iMsg
  Set .Configuration = iConf
      .To = """susan""susan@public.wh.hb.cn"
      .From = """zeki""zeki@tom.com"
      .Subject = "Hows it going? I've attached my web page"
      .CreateMHTMLBody "http://www.wuhan.net.cn"
      .AddAttachment "G:/mapiwp.txt"
      .Send
End With
成功发送邮件,而且和outlook express再也没什么联系,太好了,继续学习!

原创粉丝点击