troubleshooting Question

CFOBJECT & CDOSYS

Avatar of dapperry
dapperry asked on
Web Development SoftwareColdFusion Language
5 Comments1 Solution348 ViewsLast Modified:
Hi,

I am trying to use CFOBJECT in order to send email using CDOSYS instead of using CFMAIL. The company I am contracting for is only using CF 5 (ugh). I've seen code online that describes its use, but I can not find any where an smtpserver, and port are specified. I was hoping someone could help. Here;s what I got, which I think should work, but doesn't:

<cfscript>
      Mailer = createobject("COM","CDO.Message");
      Mailer.From = SenderAddress;
      Mailer.Subject = SubjectLine;
      Mailer.To = SendTo;
      Mailer.HTMLBody = holdMessage;
      Mailer.TextBody = holdMessageTextOnly;
      if (len(Attachments) gt 0)
      {
            Mailer.AddAttachment(Attachments);
      }
      MailConfig= createobject("COM","CDO.Configuration");
</cfscript>
<cfset fields = MailConfig.Fields">
<cfloop collection="fields" item="item">
      <cfif item.name is "http://schemas.microsoft.com/cdo/configuration/sendusing">
            <cfset item.value = 2>
      </cfif>
      <cfif item.name is "http://schemas.microsoft.com/cdo/configuration/smtpserver">
            <cfset item.value = "10.0.0.12">
      </cfif>
      <cfif item.name is "http://schemas.microsoft.com/cdo/configuration/smtpserverport">
            <cfset item.value = 25>
      </cfif>
</cfloop>
<cfset MailConfig.Fields.Update()>
<cfset Mailer.Configuration = MailConfig>
<cfset Mailer.send()>
<cfset Mailer = nothing>

I keep getting an error, which point to the cfloop line:

Invalid collection fields - must be a valid struct or COM object


Any help would be much appreciated.

:) David
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros