Help get this topic noticed by sharing it on Twitter Twitter, Facebook Facebook, or email.
tushar.g.mangukiya

Email Template - replace sub value of header

Hello,
My application is in ASP.NET C#.
I have set email template in my SendGrid account as below.
--------------------

Hi.. ##FIRSTNAME## ##LASTNAME##.
---------------------
Now from my application in header I am passing
{\"sub\":{\"##FIRSTNAME##\":[\"xyz\", \"abc\"],\"##LASTNAME##\":[\"123\",\"456\"],\"##LINK##\":[\"www.google.com\",\"www.yahoo.com\"]}

But unfortunately values are not replaced.
Now if I passed body from my application with these sub, then it is replacing correctly.
So how can I resolved this issue?
Any help will be appreciated a lot.
Thanks in advance.
1 person has
this problem
+1
Reply

  • Jacob (Support Engineer) January 19, 2012 14:39
    If that's your full X-SMTPAPI string, you're missing a closing }
    One tool we often use is the JSONLint validator to make sure the full string is proper.

    If that doesn't help, my other suggestion would be to avoid using the hashes, since they're often also used in programming. Try using % or * instead.
    You don't even need to use special characters, just a unique string, since our system will sub everywhere it finds it. Some easier strings would just be: subfirstname, sublastname, sublink.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • tushar.g.mangukiya
    Thanks a lot Jacob for reply.

    But I have also tried by using %tag%, still it's not working.
    Right now my EmailTemplate content is
    -----------------------------
    %FIRSTNAME% ... %LASTNAME% ... <% body %>
    -----------------------------
    Can you please tell me my email template content in SendGrid is right or not?
    And one more thing is that "<% body %>" put your email content in with this tag. What does it mean?

    Because if I pass that same text from my c# app in body then it is replacing both values but if I am not passing/blank body from c# then it is not replacing SUB values in SendGrid template.

    And my whole header content is like this
    ---------------------------
    string stHeader = {\"to\":[\"xyz@yahoo.com\"],\"sub\":{\"%FIRSTNAME%\":[\"xyz\"],\"%LASTNAME%\":[\"123\"],\"%LINK%\":[\"www.google.com\"]}}

    msg.Headers.Add("X-SMTPAPI", stHeader);
    -------------------------
    I think my header content is perfectly ok because I am getting email to my account which I am passing in "to : [xyz@yahoo.com]".

    And if I add "msg.Body = "%LINK%";" then it is replacing LINK by "www.google.com".

    Can you please tell me what is wrong?
    Am I missing anything? Id my EmailTemplate wrong?

    Again thanks.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated

  • Jacob (Support Engineer) January 25, 2012 15:22
    Email template app can't take sub variables from the X-SMTPAPI header.

    Email template app is meant to look like:

    Static HTML Header

    Static HTML Footer

    Then, you send your message like so:
    X-smtpapi: sub vairalbes, etc
    body with sub tags.

    When our system gets it, it applies the substitution tags, then wraps it in the email template, putting the full message content where the tag is in the email template.

    The Email Template app is intended as a static wrapper, best used for a company logo header, or basic footer.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated