Re: Using an email script token in the subject line

Phillip_Wild
Level 10

Using an email script token in the subject line

Tricky one here. I've used an email token to spit out a variable in an email program. But in Apple Mail and Outlook 2014 there are weird spaces inserted before and after the token. See below.

Email Script Issue.jpg

The token is £100 GBP. The random spaces are definitely not part of the code.

Weird things I found out:

* When I simply put the plain text of "£100 GBP" as the output of the email script, the weird spaces remain. So it's nothing to do with my code.

* When I use a Plain Text token instead of an Email Script token (effectively making the token static), it works fine.

This might be something purely in Apple Mail and Outlook (it looks fine in Outlook365.com, interestingly enough), but in any case I can't risk it. I had to use an alternative subject line instead of something dynamic.

Has anyone encountered this before? I've asked Support but basically since it's to do with email rendering they have said they can't help me.

Phil

Tags (1)
14 REPLIES 14
Scott_McKeighe2
Level 5

Re: Using an email script token in the subject line

Did you try making the entire string part of your Email Script token, not just the £100 GBP ? I'd try that to see if it alleviates the rendering issue.

Phillip_Wild
Level 10

Re: Using an email script token in the subject line

Weirdly, that's giving me a different error. Every variant has a currency in it (either a dollar, pound or euro sign) and when I put the entire string in the email script output, then put only the token in the subject line, then it either:

1. Shows "£100" if the string was meant to be "(string) £100 GBP (string)"

2. Shows "100" if the string was meant to be "(string) $100 (string)"

I think this is because Velocity is interpreting the string as purely the variable name. For example, I'm using lines such as:

#set ($LifetimeDepositFormatted = "Don't forget your £100 GBP Lifetime Deposit!") or

#set ($LifetimeDepositFormatted = "Don't forget your $250 NZD Lifetime Deposit!")

This might be interacting with the subject line in strange ways.

Edward_Unthank_
Level 10

Re: Using an email script token in the subject line

Innnnnnteresting. I don't know why, but here could be some guesses for troubleshooting and finding the problem.

Can you count the number of spaces? Could be the scripting token is counting whitespace and rendering it in the subject line. Aka something like "echo '$100';" might count an extra whitespace.

Do you have the same problem if you just output the response (no code in the email script) with just "100" and not the special character?

Edward

tamasvadasz
Level 1

Re: Using an email script token in the subject line

Hi!

I ran into the same issue. Try using a minifier tool on your code, it removes the fluff by removing all indentations.

Worked for me just fine. I've used this site: https://www.toptal.com/developers/javascript-minifier

SanfordWhiteman
Level 10 - Community Moderator

Re: Using an email script token in the subject line

This doesn’t relate to indentation. It relates to the reserved Velocity character $ which must be escaped as ${esc.d}.

Michael_McGowa1
Level 3

Re: Using an email script token in the subject line

If you are using a script token in the subject line, and also in the body, and the script is formatting the number to currency, is there a way to code this so that this spacing in the subject line does not happen?

 

This is what I have in script for the total

#set($total = $number.currency(${subtotal})) 
#set($stringLength = $total.length() - 3) 
#set($totalb = $total.substring(0,$stringLength)) 
${totalb}

 

I have also tried just using number formatting instead of the currency formatting i.e.

#set ($formattedTotal = $number.format("number", $subtotal))
${esc.d}${formattedTotal}

Yet, I still get the space in the subject line.

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Using an email script token in the subject line

You can Q-encode the dollar sign when using it in the Subject.

#set ($formattedTotal = $number.format("number", $subtotal))
=?UTF-8?Q?${esc.d}?=${formattedTotal}

 

Though in fact I can’t reproduce what you’re saying about the extra space, even without Q-encoding. Can you paste the exact raw source of the Subject line, as received in your email client (i.e. View Original/View Raw/etc.)?

Michael_McGowa1
Level 3

Re: Using an email script token in the subject line

I tried this but I am still seeing the issue. Here is a screenshot of the subject line

subjectline.png

I will also say that the month is also a token so when you look at it in the subject line it  is

{{my.month}} No-Essay Scholarships Worth {{my.dollarAmt}}

SanfordWhiteman
Level 10 - Community Moderator

Re: Using an email script token in the subject line

Please provide the entire text of your Velocity token, without trimming it at all. (And use the syntax highlighter, as you did above.)