Custom variable/macro in an email template that gets populated programatically

Kentico User asked on February 4, 2016 17:30


So it appears that I cannot do what I am trying to do here

What I would like to do now is to create a custom macro in my email template and have its value get replaced when the biz form is submitted.

This version of the macro is no longer supported


 string[,] macros = new string[,] { 
                { "{#text1#}", node1.GetStringValue("AnswerExplanation", "") }, 
                { "{#text2#}", node2.GetStringValue("AnswerExplanation", "") },
                { "{#text3#}", node3.GetStringValue("AnswerExplanation", "") },
                { "{#text4#}", node4.GetStringValue("AnswerExplanation", "") },
                { "{#text5#}", node5.GetStringValue("AnswerExplanation", "") },
                { "{#text6#}", node6.GetStringValue("AnswerExplanation", "") }};

                MacroResolver macroResolver = new MacroResolver();
                 EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("TakeTheTestAutoResponder", CMS.SiteProvider.SiteContext.CurrentSiteID);

            EmailMessage emailMessage = new EmailMessage();
            emailMessage.EmailFormat = EmailFormatEnum.Html;
            emailMessage.Recipients = emailFieldValue;
            emailMessage.From = eti.TemplateFrom;
            emailMessage.Subject = eti.TemplateSubject;
            EmailSender.SendEmailWithTemplateText(CMS.SiteProvider.SiteContext.CurrentSiteName, emailMessage, eti, macroResolver, true);

Can you please point to some kind of a documentation to use new macros within an email and have it resolve programmatically?

Thank you,

Recent Answers

Brian McKeiver answered on February 4, 2016 17:36

I have some code at the bottom of the blog post that adds a custom macro into an email template. Check out the GetCurrentEmailTemplateTextAsXml function in there.

1 votesVote for this answer Mark as a Correct answer

Zachary Perry answered on February 4, 2016 19:42 (last edited on February 4, 2016 19:43)

Are you trying to add a macro to the autoresponder email? or are you sending an email via custom code?

If you are using custom code, Brian's blog post will help accomplish that.

If you just want to add a macro to the autoresponder email, you can click on the {#} and build a macro. If you want to get data from documents you can do something along these lines:

{% Documents.WithAllData["/Special-pages"].Children["Forum-unsubscribe"].DisplayName %}

If you want to create a custom macro, and need documentation on how to do that. This should Help

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.