Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason Prothero 416 posts 1226 karma points c-trib
    Aug 19, 2009 @ 17:54
    Jason Prothero
    0

    Adding newlines in macro parameters

    Hello,

    I've built a Contact Form user control for a site I'm building with Umbraco and I have a few custom parameters that allow for customization of the email sent to the company.

    The macro looks like this when inserted into a template:

    <umbraco:Macro DestinationEmail="[email protected]" Subject="Corporate Website Contact" EmailMessageFormatString="Name: {0}%0D%0ACompany: {1}\r\nEmail: {2}\r\nPhone: {3}\r\n\r\nMessage:\r\n---------------------\r\n{4}\r\n" ThankYouMessageString="Thank you.  Your message has been sent successfully.  We will get back to you within 2 business days." Alias="ContactForm" runat="server"></umbraco:Macro>

    I'm trying to figure out how I can insert a new line code into the EmailMessageFormatString parameter so that the email sent has some formatting and its not all run together.  I suppose I could make the email html formatted and use markup, but this was a question I could not find an answer to.

    Any thoughts? Can a new line be encoded into the EmailMessageFormatString?

     

    Thanks,

    Jason

  • Chris Koiak 700 posts 2626 karma points
    Aug 19, 2009 @ 18:15
    Chris Koiak
    0

    Hi Jason,

    I'm unclear, does the above approach work?

    If not I would use a special textual marker in the EmailMessageFormatString like EmailMessageFormatString="Name: {0}%0D%0ACompany: {1}<<nl>>Email: {2}\r\nPhone: {3}<<nl>>Message:<<nl>>---------------------<<nl>>{4}<<nl>>"


    Then, before the email is sent I would string replace the marker

    string messageBody = EmailMessageFormatString.Replace("<<nl>>", Environment.NewLine);

    New line characters are respected in a non-html email. If this still isn't working then double check your not already trying to send the email as html.

  • Jason Prothero 416 posts 1226 karma points c-trib
    Aug 19, 2009 @ 18:47
    Jason Prothero
    0

    Yea, neither of the newline attempts in my original question worked. 

    The newline replacement idea is a good one.  I tested that and it works great.  Thanks for the response.

     

    Should those "\r\n"s work in a macro param?  Do they need to be encoded?

     

  • Chris Koiak 700 posts 2626 karma points
    Aug 19, 2009 @ 20:49
    Chris Koiak
    0

    I'm not too sure about passing "\r\n" as a macro param. It should have worked as it's the same as Environment.NewLine.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Aug 19, 2009 @ 21:03
    Dirk De Grave
    0

    Hi guys,

     

    Isn't this something similar...  http://our.umbraco.org/forum/developers/xslt/3240-dreaded-rn-has-re-appeared?p=1

    No real solution currently, as people are still trying to lock down the issue

     

    Cheers,

    /Dirk

  • Jason Prothero 416 posts 1226 karma points c-trib
    Aug 19, 2009 @ 23:46
    Jason Prothero
    0

    Yea, I'm now noticing wierd /r/n appearing randomly in the macro params when I insert in into a richtext editor.

     

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 20, 2009 @ 10:16
    Darren Ferguson
    2

    Can I suggest that you put your email template in a configuration file and pass the filename as the parameter to the macro?

    IMHO it makes your template code a lot more readable!

     

     

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 20, 2009 @ 10:20
    Darren Ferguson
    0

    To expand on my previous post, your Macro would read the file from the filesystem and you could edit it through the Umbraco GUI using Tim G's config tree package.

  • Jason Prothero 416 posts 1226 karma points c-trib
    Aug 21, 2009 @ 00:34
    Jason Prothero
    0

    I'll take a look at the config tree package and see if I can get that to work.

     

    Thanks

  • Jason Prothero 416 posts 1226 karma points c-trib
    Feb 16, 2010 @ 18:09
    Jason Prothero
    0

    BTW, the config file solution worked like a charm.  Thanks Darren!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies