mapi与cdo

因为要用到消息编程,于是考察了一下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再也没什么联系,太好了,继续学习!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值