Macros not resolved with using SendEmailWithTemplateText

Jay McCormack asked on November 6, 2014 07:52

We recently upgraded a site from K6 to K8.1 - and this functionality worked in K6.

We have an email template stored in kentico that is loaded through the API and some adhoc values merged into it using the macroresolver. It appears now though in K8.1 that this no longer works. The template is loaded and the values are added in the same way but the output of the email does not contain the resolved data.

Here's our code:

 EmailMessage msg = new CMS.EmailEngine.EmailMessage();
 EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("3DNPaymentSucessEmail", 0);

 MacroResolver mcr = new MacroResolver();

 var SourceParameters = new string[,] { 
            { "UserName", sUserName }, 
            { "PaymentAmount", sPaymentAmount },
            { "ReferenceNumber", sReferenceNumber }
        };
 mcr.AddAnonymousSourceData(SourceParameters);

 msg.EmailFormat = EmailFormatEnum.Both;
 msg.Recipients = sEmailAddress;

 EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, msg, eti, mcr, true);

Any ideas on why it stopped working and any suggestions on how to get it running again?

Thanks

Jay

Recent Answers


Sunil Sharma answered on November 6, 2014 12:08

This can help you.

EmailMessage msg = new CMS.EmailEngine.EmailMessage();

EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("ToApplicant", SiteContext.CurrentSiteName);

MacroResolver mcr = MacroResolver.GetInstance();

mcr.SetNamedSourceData("Name", txtApplicantFName.Text.ToString());

mcr.SetNamedSourceData("TITLE", txtPosition.Text.ToString());

msg.EmailFormat = EmailFormatEnum.Both;

msg.From = eti.TemplateFrom;

msg.Recipients = txtEmail.Text.ToString();

msg.Subject = eti.TemplateSubject;

string attachment = string.Empty;

EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, msg, eti, mcr, true);

0 votesVote for this answer Mark as a Correct answer

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