Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send e-mail Automating CDO

COM and Automation

How to send e-mail Automating CDO

by  Mike Gagnon  Posted    (Edited  )
*/*CDOSYS.dll comes with Windows 2000 and XP

There reason CDO2.0 avoids the security patch of Outlook is, it does not require Outlook to work. (Thank you Jonscott8 for this clarification)
Note #1 : This requires SMTP services installed and running on the local computer.
Note: If a mail server is involved (ie: Exchange server ) consider using the suggestions in faq184-1769.

Code:
oMSG = CREATEOBJECT('cdo.message')
oMSG.To = 'me@nowhere.com'
oMSG.From = 'me'
oMSG.Subject = 'Hello Email'
oMSG.TextBody = 'This is an easy way to create an email'
oMSG.Send()

*/*Here are some other features of the CDO.Message:

Code:
oMSG = createobject('CDO.Message')
oMSG.To = 'me@nowhere.com'
oMSG.From = 'me@nowhere.com'
oMSG.Subject = 'Hello Email'
oAtt=oMSG.AddAttachment('c:\myfile.txt')
oMSG.Send()

*/*Here is a great way to embed your web page in your email:

Code:
oMSG = createobject('CDO.Message')
oMSG.To = 'me@nowhere.com'
oMSG.From = 'me@nowhere.com'
oMSG.Subject = 'Hello Email'
oMSG.CreateMHTMLBody('http://www.slpcanada.com')
oMSG.Send()

*/*Here is another way to send HTML in your email:

Code:
oMSG = createobject('CDO.Message')
oMSG.To = 'me@nowhere.com'
oMSG.From = 'me@nowhere.com'
oMSG.Subject = 'Hello Email'
oMSG.HTMLBody = [< b >< P >< FONT COLOR='#CC0000' >Hello In Color< /FONT >< /b >]
oMSG.Send()

*/* How to create an MHTML document using CDO.

Code:
Local lcFileName,lcStr
Declare Integer ShellExecute In "Shell32.dll" ;
	INTEGER HWnd, ;
	STRING lpVerb, ;
	STRING lpFile, ;
	STRING lpParameters, ;
	STRING lpDirectory, ;
	LONG nShowCmd
lcFileName = Sys(2015)+'.mht'
oMSG = Createobject("CDO.Message")
oMSG.CreateMHTMLBody("http://www.microsoft.com")
lcStr = oMSG.getstream
lcStr.SaveToFile(lcFileName,1)
ShellExecute(0,"Open",lcFileName,"","",0)

Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top