Windows.XP.in.a.Nutshell.1002005.2Ed [Electronic resources]

نسخه متنی -صفحه : 239/ 219
نمايش فراداده

9.18. Messaging

Messaging services (email) can be accessed using CDO (Collaborative Data Objects). This COM object contains a large and powerful selection of objects.

CDO is a powerful but complex object model. The web site, CDO Live, at http://www.cdolive.com, is an excellent resource to get you started working with CDO.

The following example will log on to your default messaging profile and send a message. This assumes you are using an Exchange or Outlook client that has been set up to send Internet email. This will not work with Outlook Express.

Dim objSession, objMessage, WshShell, sPrf, objRecipient
Set WshShell = CreateObject("WScript.Shell")
'create a MAPI session
Set objSession = CreateObject("MAPI.Session")
'check if the OS string contains NT
'set the profile string. This will read your default setting
sPrf = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging
Subsystem\Profiles\DefaultProfile"
'log on using the default profile name
objSession.Logon WshShell.RegRead(sPrf)
'create a new message, setting the subject to Hello There
Set objMessage = _
objSession.Outbox.Messages.Add("Hello There")
objMessage.Text = "This is the body of the message"
'send to Joe Blow
Set objRecipient = objMessage.Recipients.Add("Joe Blow", _
"SMTP:joeb@abc.com")
objRecipient.Resolve 'resolve the address
'send the message
objMessage.Send
objSession.Logoff