I'm trying to get information from the contact in code behind the rendering I placed in the EXM message. I currently have a Sitecore form that has only one field, an email field. When submitted it sends an automated email to the email address inputted by the user. In the email body, I put a controller rendering that calls a view.

The Controller rendering looks like this, I'm currently just getting the query string parameters and putting it on the model for the view to show.

public class VerificationController : Controller
    public ActionResult VerificationKey()
        using (var client = SitecoreXConnectClientConfiguration.GetClient())
            string check = "unchanged", check2 = "unchanged", check3 = "unchanged", check4 = "unchanged", check5 = "unchanged", check6 = "unchanged", check7 = "unchanged";
                check = System.Web.HttpContext.Current.Request.QueryString["ec_subscr"] == null ? System.Web.HttpContext.Current.Request.QueryString["ec_subscr"] : "check is NULL";
                check2 = System.Web.HttpContext.Current.Request.QueryString["ec_contact_id"] == null ? System.Web.HttpContext.Current.Request.QueryString["ec_contact_id"] : "check2 is NULL";
                check3 = System.Web.HttpContext.Current.Request.QueryString["ec_emailid"] == null ? System.Web.HttpContext.Current.Request.QueryString["ec_emailid"] : "check3 is NULL";
                check4 = System.Web.HttpContext.Current.Request.QueryString["ec_lang"] == null ? System.Web.HttpContext.Current.Request.QueryString["ec_lang"] : "check4 is NULL";
                check5 = System.Web.HttpContext.Current.Request.QueryString["ec_message_id"] == null ? System.Web.HttpContext.Current.Request.QueryString["ec_message_id"] : "check5 is NULL";
                check6 = System.Web.HttpContext.Current.Request.QueryString["ec_recipient"] == null ? System.Web.HttpContext.Current.Request.QueryString["ec_recipient"] : "check6 is NULL";
                check7 = System.Web.HttpContext.Current.Request.QueryString["ec_id"] == null ? System.Web.HttpContext.Current.Request.QueryString[" ec_id"] : "check7 is NULL";
            catch (Exception ex)
                Sitecore.Diagnostics.Log.Error(ex.Message, ex, "VERIFICATION CONTROLLER");
            var verificationLink = new VerificationLink();

            //LOGIC For Generating Unique key here
            verificationLink.UniqueKey = check + "|" + check2 + "|" + check3 + "|" + check4 + "|" + check5 + "|" + check6 + "|" + check7;

            return View(verificationLink);

The View is much simpler, it's just to output what I got from the controller

@model Sample.Namespace.VerificationLink
@{ string uniqueKey = Model.UniqueKey; }
<div>This is the Unique Key: @uniqueKey</div>

When I try to send the email from the form. This is the result enter image description here

I'm expecting that the query strings would give me the information I need for the contact but it seems they're all null or empty.

  • So, you are trying to use Sitecore Forms... The Contact Filling out the form has to be a Known Contact. If the form is being filled out by an anonymous contact, EXM won't send any message because there's no email address for the user. You'll want to create a custom submit action to identify the contact filling out the form and set the Email facet for the Preferred Email address. Jul 3 '19 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.