8 Replies Latest reply on Jan 29, 2009 6:59 AM by kenji776

    Dynamic Email Message

    kenji776 Level 1
      Hey guys,
      I am trying to write a small email tool that is basically a mail merge. The user types what they want, tell it what table they want it to pull user information from and it goes. however, I want the email they write to be able to use information found in the table to they specify. So if the query that pulled the info was called "UserInfo" and it had a field called firstname, I would like the user to be able to type in the box

      Hello #firstname#,
      blah blah blah.

      and the message would be evauluated for each email that gets sent out. Right now when I type that into the textbox, and echo it out, it simple says

      Hello #firstname#,

      instead of actually parsing the value of firstname. How can I force it to parse the values of things in # #? I tried using evaluate on the whole message, but of course that doesnt work. Keep in mind I am using the richtext editor.

      Attached is my code so far.
        • 1. Re: Dynamic Email Message
          Dan Bracuk Level 5
          For the view, then send part, think about what you can do with cfsavecontent in the session scope.

          For the selection of tables and fields, you are asking for trouble if you want the users to type these. Maybe related selects are a better option.
          • 2. Re: Dynamic Email Message
            kenji776 Level 1
            Dan,
            Good though about it being a bad idea having the type that in. I think there is a table that has all the ID's that would be valid for that box, so I can probably just turn that into a drop down.

            I hate to sound like a leech here, but could you maybe provide a bit of sample code for what you are thinking about with the sessions and the savecontent? I just don't follow your train of thought. Thanks for your help so far, I really appreciate it.
            • 3. Re: Dynamic Email Message
              Dan Bracuk Level 5
              <cfsavecontent variable="session.x">
              cold fusion and html code goes here
              </cfsavecontent>

              <cfoutput>#session.x#</cfoutput>

              Also bear in mind that cfmail is in some ways equivalent to cfoutput.
              • 4. Re: Dynamic Email Message
                kenji776 Level 1
                Thanks for the tip, Ill try and write something real quick and see how it goes. I'll let ya know how it turns out.
                • 5. Dynamic Email Message
                  kenji776 Level 1
                  Dan,
                  Well I tried. Sadly I'm just having a hard time wrapping my brain around this. I know its not hard, but I'm just not comprehending.

                  Here is a link to the demo app
                  http://www.digitalswordsmen.com/dynamicformtest.cfm

                  And attached is my code. I tried with and without CFOUTPUT around the SAVECONTENT but it didn't work either way. I just wrote a super simple demo app. Basically you should be able to enter #Firstname# in there, and it will then evaluate that when it outputs it to the screen, but it does not.

                  As a side note, if the info didn't have to come from a form box, your original idea works beutifully. You can type text and variables in there, and it does exactly what you would expect it to do. However, when you feed the form variable into there, it does not parse the variables, inside of the variable. It gets passed #form.Myletter# and it just slaps that in there, it doesn't look inside #form.Myletter# to see if there is anything in there that needs evaluation. I really have no idea how to get around that.
                  • 6. Dynamic Email Message
                    kenji776 Level 1
                    Awesome, I figured it out!
                    Sorry for the triple post, but I wanted to post my solution in case anyone else can benefit from it. If you are trying to allow a person to write a letter or something and let them use variables, something like the following works pretty well. This is a super simple demo app to show off what Im talking about. I hate that I have to use evaluate, but i don't think i had a choice here.
                    • 7. Re: Dynamic Email Message
                      -==cfSearching==- Level 4
                      > #evaluate("GetFields.#column#")#

                      You do not have to use evaluate. Use array notation:

                      #queryName[columnName][rowNumber]#

                      That said, you might consider obfuscating the column names, rather than exposing your database schema.
                      • 8. Re: Dynamic Email Message
                        kenji776 Level 1
                        Hey sweet tip about getting around using evaluate. I didn't think I could use array notation like that. I would do something about hiding the database scheme, however I would then need to create some kind of like metadata table that has alternate names for the column names, and that would be kinda a pain. This is an internal only use tool (only for about 3 people here in the office) and it will be secured. I'm not even sure most people would know that those field names correlate to database column names. I suppose more astute users might be able to figure that out. I'll think about it, but sounds like more worth than it's worth :P