Using the CDOSYS COM Object in ColdFusion
Saturday, November 13, 2004
I recently had to use the CDOSYS object in Cold Fusion. Using COM Objects in Cold Fusion can get tricky. After some trial and error I have figured out its quirks.
Cold Fusion won’t let you reference nested objects more than one level deep. In using CDOSYS I needed to set an object.property("named_property") value.
Using the CDOSYS object as an example:
Normally:
Flds.Item("urn:schemas:mailheader:FOO") = “somevalue”
In Cold Fusion:
mailheader = Flds.Item("urn:schemas:mailheader:FOO");
mailheader.value = “somevalue”;
Not a major deal, but this isn?t documented anywhere.
Full Code Example:
<cfscript>
objMail=CreateObject("COM”,"CDO.Message");
objMail.To="#to#";
objMail.CC="#cc#";
objMail.BCC="#bcc#";
objMail.From="#from#";
objMail.Subject="#subject#";
objMail.ReplyTo="#replyTo#";
if (#emailtype# EQ “HTML")
{
objMail.HTMLBody="#body#";
} else {
objMail.TextBody="#body#”;
}
// If you have an attachment, another CF quirk
// is all parameters of an object must be passed.
objMail.AddAttachment("#filename#”,"","");
// Set a custom header field, in this case “foo”
// with the value “somevalue”
iFlds = objMail.Fields;
mailheader = iFlds.Item("urn:schemas:mailheader:foo");
mailheader.value = “somevalue”;
iFlds.Update();objMail.Send();
objMail="”;
</cfscript>
If you have any questions please feel free to write.
PFFFTTT ... Coldfusion is so mid-90’s!
This was basiclly a form mailer for email containing an attachment?
Posted by web on 11/15 at 10:52 AMCorrect using CDOSYS instead of CFMAIL. CFMAIL has always had issues. The project I am working on called for its replacement.
I agree CF has run its course. I actually worked for Allaire for CF 3.0 through CF 4.5.
Posted by Brian on 11/15 at 11:20 AMCF was great. It was the first server side technology I used .. and at the time .. it was perfect for what we needed.
I still have a place in my heart for my first server side web technology.. I remember running through fields of daisies with her .. [siiiigggghhhhhh]
After time we grew apart .. CF became angry and started to act like a jilted ex girlfriend. I had to end it. But I will never forget the good times ...
[singing]
M-M-M-M-Mem’ries light the corners of my mind
Misty water-colored mem’ries of the way we were!!!
[/singing]I promised you I wouldn’t sing on your site ever again .. I guess I lied.
Posted by Web on 11/15 at 01:19 PMYou people need to have sex with something. Like, immediately.
Posted by Billy on 11/29 at 09:32 AM