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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Generation of CFMAIL attributes

Status
Not open for further replies.

thysonj

Programmer
Jul 6, 2001
240
US
I am building a custom tag for auto emailing and I have gotten stuck at the actual generation of the email. You see right now my tag would accept any cfmail attribute available. The problem is that when I attempt to send the email with cfmail I need to use the attributes they ACTUALLY specified. I can't generate the attributes dynamically without generating a JIT error(ie:i cant loop through a list or collection and output them.) and I cant set them equal to form variables because some of them cannot be specified and set to nothing. Any ideas??
 
i use this custom tag to send me a message when the site breaks ...
here is the tag
*********************************************
<!--- Set Variable Defaults --->
<cfparam name=&quot;attributes.to&quot; default=&quot;#request.adminEmail#&quot;>
<cfparam name=&quot;attributes.from&quot; default=&quot;#request.adminEmail#&quot;>
<cfparam name=&quot;attributes.type&quot; default=&quot;na&quot;>
<cfparam name=&quot;attributes.message&quot; default=&quot;na&quot;>
<cfparam name=&quot;attributes.detail&quot; default=&quot;na&quot;>
<cfparam name=&quot;attributes.TagContext&quot; default=&quot;na&quot;>

<!--- Send Email Alert With Debug Info --->
<cfmail to=&quot;#attributes.to#&quot; from=&quot;attributes.from&quot; subject=&quot;Broken Report&quot; type=&quot;HTML&quot;>
#attributes.Type#<br>
#attributes.Message#<br>
#attributes.Detail# <br>
<P>The contents of the tag stack are:</P>
<cfloop index = i from = 1 to = #ArrayLen(attributes.tagContext)#>
<cfset sCurrent = #attributes.tagContext#>
<BR>#i# #sCurrent[&quot;ID&quot;]#
(#sCurrent[&quot;LINE&quot;]#,#sCurrent[&quot;COLUMN&quot;]#)
#sCurrent[&quot;TEMPLATE&quot;]#
</cfloop>
</cfmail>
****************************************

and i call it like so....

<cfcatch type=&quot;any&quot;>
<cf_email_warning to=&quot;#request.adminEmail#&quot; type=&quot;#cfcatch.Type#&quot; message=&quot;#cfcatch.Message#&quot; detail=&quot;#cfcatch.Detail#&quot; TagContext=&quot;#cfcatch.TagContext#&quot;>
<cflocation url=&quot;#request.errorPage#&quot; addtoken=&quot;no&quot;>
</cfcatch> ------------------------------------------------------------------------------
brannonH
if( !succeed ) try( );
 
> The problem is that when I attempt to send the email
> with cfmail I need to use the attributes they
> ACTUALLY specified.

I'm not exactly sure what you're asking... but it sounds like you're having a common problem.

You certainly CAN generate attributes dynamically... if you need to create a to: attribute out of a list of addresses, you create the list first:
Code:
<CFSET myAddressees = &quot;&quot;
<CFLOOP ... whatever>
   <CFSET myAddressees = ListAppend(&quot;#myAddressees#&quot;,anotherAddress)>
</CFLOOP>

<CFMAIL to=&quot;#myAddressees#&quot; ...>

If you need to send cc:s or bcc:s depending on a given set of circumstances (ie - only send a cc if a given option is selected), you have to use CFMAILPARAM rather than CFMAIL's built in cc parameter since CFMAIL doesn't like it when you pass cc or bcc an empty string.
Code:
<CFMAIL to=&quot;#myAddressees#&quot; ...>
   <CFIF needToSendCC EQ true>
       <CFMAILPARAM name=&quot;Cc&quot; value=&quot;someaddress@somedomain.com&quot;>
   </CFIF>
        :
        :
</CFMAIL>

-Carl
 
My problem is this exaclty..
Say when I call the tag I want to specify a BCC. Keep in mind they do not have to. Eventually I will need that in the cfmail. It is easy just to have that parameter(BCC) in cfmail and set it to attributes.bcc. Where the problem is when they don't specify that. Then I have a cfmail tag that expects a bcc attribute that doesn't exist. I need to be able to create the parameters dynamiclly depending on what they do specify. If they set a type then it puts the type parameter in the cfmail tag and sets it to attributes.type. But if they don't specify the type then the type parameter needs not be put in the cfmail tag. Actually when it comes to cc.bcc.type etc...this has not been a problem because they CAN be empty. Where the biggest propblem is with parameters like query and startrow that cannot be empty.
 
As I said... the solution is to use CFMAILPARAM tags, rather than the attributes of the CFMAIL tag itself:

Code:
<!--- don't put cc= or bcc= in the CFMAIL tag --->
<CFMAIL to=&quot;#myAddressees#&quot;>
   <CFIF needToSendCC EQ true>
       <CFMAILPARAM name=&quot;Cc&quot; value=&quot;someaddress@somedomain.com&quot;>
   </CFIF>
   <CFIF needToSendBCC EQ true>
       <CFMAILPARAM name=&quot;Bcc&quot; value=&quot;someotheraddress@somedomain.com&quot;>
   </CFIF>

        :
        :
</CFMAIL>
-Carl
 
i tried implementing this and i can generate the cfmailparams but none of them seem to do anything...???
 
I have been able to get the cfmailparams into the cfmail but they are not executing.

For example i can insert a cc header and it will show up in the email but the cc will not happen.

any ideas????
 
Grrrr... you're right thysonj... so sorry for leading you down that path. Apparently &quot;Cc&quot; and &quot;Bcc&quot; are actually false headers. A mail client actually interprets these and sticks them into a RCPT TO header before it sends the mail.

My bad.

However, here's a second solution to make it up to you ;-)


Code:
<CFSAVECONTENT var=&quot;emailBody&quot;>
    #attributes.Type#<br>
    #attributes.Message#<br>
    #attributes.Detail# <br>
    <P>The contents of the tag stack are:</P>
    <cfloop index = i from = 1 to = #ArrayLen(attributes.tagContext)#>
      <cfset sCurrent = #attributes.tagContext#>
           <BR>#i# #sCurrent[&quot;ID&quot;]# 
        (#sCurrent[&quot;LINE&quot;]#,#sCurrent[&quot;COLUMN&quot;]#) 
        #sCurrent[&quot;TEMPLATE&quot;]#
    </cfloop>
</CFSAVECONTENT>

<CFIF IsDefined(&quot;cclist&quot;) and Len(Trim(cclist)) GT 0>
   <CFIF IsDefined(&quot;bcclist&quot;) and Len(Trim(bcclist)) GT 0>
      <CFMAIL to=&quot;#tolist#&quot; cc=&quot;#cclist#&quot; bcc=&quot;#bcclist#&quot;>
         #emailBody#
      </CFMAIL>
   <CFELSE>
      <CFMAIL to=&quot;#tolist#&quot; cc=&quot;#cclist#&quot;>
         #emailBody#
      </CFMAIL>
   </CFIF>
<CFELSE>
   <CFIF IsDefined(&quot;bcclist&quot;) and Len(Trim(bcclist)) GT 0>
      <CFMAIL to=&quot;#tolist#&quot; bcc=&quot;#bcclist#&quot;>
         #emailBody#
      </CFMAIL>
   <CFELSE>
      <CFMAIL to=&quot;#tolist#&quot;>
         #emailBody#
      </CFMAIL>
   </CFIF>
</CFIF>

Not terribly pretty, but it works.


-Carl
 
While i think your second solution would surely work it unfortunately is not an option here as I am trying to allow users to specify any of the 16 params avaiable to cfmail. setting up if else statements with that many options presents far too many permutations for practical use. I believe i am simply up a creek as they say and will need to redefine the functionality i want to offer.
Thanks for the help though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top