![]() |
|
Send Mail Using CDO | |
Public Sub testCDO() ' Purpose Demondtrate Sending an Email with an attachment using CDO (Collaboration Data Objects) ' Uses Late Binding - Does not need a reference to the Microsoft CDO For Windows library ' cdosys comes innstalled as standard on Windows 2K and higher workstations and servers ' This code will fail on NT4, Win 98, and Win 95 where the cdosys.dll is not present ' Author Ron Weiner rweiner@WorksRite.com ' Copyrite © 2004-2005 WorksRite Software Solutions ' You may use this code example for any purpose what-so-ever with ' acknowledgement. However, you may not publish the code without ' the express, written permission of the author. Const cdoSendUsingPort = 2 Const cdoBasic = 1 Dim objCDOConfig As Object, objCDOMessage As Object Dim strSch As String strSch = "http://schemas.microsoft.com/cdo/configuration/" Set objCDOConfig = CreateObject("CDO.Configuration") With objCDOConfig.Fields .Item(strSch & "sendusing") = cdoSendUsingPort .Item(strSch & "smtpserver") = "SMTP.ServerName.Com" ' Only used if SMTP server requires Authentication .Item(strSch & "smtpauthenticate") = cdoBasic .Item(strSch & "sendusername") = "SomeMailBox@SomeDomain.com" .Item(strSch & "sendpassword") = "YourPassword" .Update End With Set objCDOMessage = CreateObject("CDO.Message") With objCDOMessage Set .Configuration = objCDOConfig .from = "Senders Pretty Name" .sender = "SomeMailBox@SomeDomain.com" .To = "SomeOne@SomeWhere.com" .Subject = "Sample CDO Message" ' Use TextBody to send Email in Plain Text Format '.TextBody = "This is a test for CDO message" ' Use HTMLBody to send Email in Rich Text (HTML) Format .HTMLBody = "Test CDO Rich Text this is not Bold But <B>This is!</B>" ' Adding Attachments is easy enough .AddAttachment "c:\SomeFile.zip" .AddAttachment "c:\SomeOtherFile.pdf" ' Un-Rem next line to get "Return Reciept Request" '.MDNRequested = True .Send End With Set objCDOMessage = Nothing Set objCDOConfig = Nothing End Sub |
Copyright © 2001 WorksRite Software Solutions -- Last Updated 06/13/05 |