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.
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
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
This doesn’t relate to indentation. It relates to the reserved Velocity character $ which must be escaped as ${esc.d}.
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.
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.)?
I tried this but I am still seeing the issue. Here is a screenshot of the subject line
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}}
Please provide the entire text of your Velocity token, without trimming it at all. (And use the syntax highlighter, as you did above.)
Hi Sanford,
Below is the full script token.
With the subject line I am seeing:
And in the body of the email I am seeing
##********Finding out if they came through the CoReg
#set ($coReg = ${lead.mktocoreg})
#set ($coReg2Scp = ${lead.mktocoreg2scp})
#if($coReg.equals("niche"))
#set ($coRegMkt = "yes")
#elseif ($coReg.equals("campusreel"))
#set ($coRegMkt = "yes")
#else
#set ($coRegMkt = "no")
#end
##********Finding out if they came through the CoReg and converted or Just Member
#if(($coReg2Scp.equals("")) && ($coRegMkt.equals("yes")))
#set ($scpMember = "Coreg Not a Member")
#elseif (($coReg2Scp.equals("1")) && ($coRegMkt.equals("yes")))
#set ($scpMember = "Coreg but member")
#else
#set ($scpMember = "Member")
#end
##******************Eligible or Taken Bold**********
#set ($takenBold = ${lead.mktotakenBold})
#set ($eligibleBold = ${lead.mktoeligiblebold})
#if (($eligibleBold.equals("1")) && ($takenBold.equals("")))
#set ($showBold = 25000)
#else
#set ($showBold = 0)
#end
##******************Eligible or Taken Juno**********
#set ($takenJuno = ${lead.mktotakenJuno})
#set ($eligibleJuno = ${lead.mktoeligiblejuno})
#if (($eligibleJuno.equals("1")) && ($takenJuno.equals("")))
#set ($showJuno = 2500)
#else
#set ($showJuno = 0)
#end
##******************Eligible or Taken Niche**********
#set ($takenNiche = ${lead.mktotakenNiche})
#set ($eligibleNiche = ${lead.mktoeligibleniche})
#if (($scpMember.equals("Coreg Not a Member")) && ($coReg.equals("niche")))
#set ($showNiche = 0)
#elseif (($eligibleNiche.equals("")) && ($coReg.equals("campusreel")) && ($takenNiche.equals("")))
#set ($showNiche = 2000)
#elseif (($eligibleNiche.equals("1")) && ($takenNiche.equals("")))
#set ($showNiche = 2000)
#else
#set ($showNiche = 0)
#end
##******************Eligible or Taken Christian Connector**********
#set ($takenCC = ${lead.mktotakenChristianConnector})
#set ($eligibleCC = ${lead.mktoeligiblechristianc})
#if (($eligibleCC.equals("1")) && ($takenCC.equals("")))
#set ($showCC = 2500)
#else
#set ($showCC = 0)
#end
##******************Eligible or Taken Nitro**********
#set ($takenNitro = ${lead.mktotakenNitro})
#set ($eligibleNitro = ${lead.mktoeligiblenitro})
#if (($eligibleNitro.equals("1")) && ($takenNitro.equals("")))
#set ($showNitro = 2000)
#else
#set ($showNitro = 0)
#end
##Adding up the dollars available
#set ($subtotal = $math.add($showNiche, $showBold, $showNitro, $showCC, $showJuno, 13000))
#set ($formattedTotal = $number.format("number", $subtotal))
=?UTF-8?Q?${esc.d}?=${formattedTotal}
There’s whitespace all throughout that code! Velocity is space-preserving. So all those line breaks end up in the output.
I took away the spaces but now the entire subject line is moving as if there is a tab space before the subject line
Also I am the encoding is still showing up in the body of the email
Any suggestions? Here is the updated code.
##********Finding out if they came through the CoReg
#set ($coReg = ${lead.mktocoreg})
#set ($coReg2Scp = ${lead.mktocoreg2scp})
#if($coReg.equals("niche"))
#set ($coRegMkt = "yes")
#elseif ($coReg.equals("campusreel"))
#set ($coRegMkt = "yes")
#else
#set ($coRegMkt = "no")
#end
##********Finding out if they came through the CoReg and converted or Just Member
#if(($coReg2Scp.equals("")) && ($coRegMkt.equals("yes")))
#set ($scpMember = "Coreg Not a Member")
#elseif (($coReg2Scp.equals("1")) && ($coRegMkt.equals("yes")))
#set ($scpMember = "Coreg but member")
#else
#set ($scpMember = "Member")
#end
##******************Eligible or Taken Bold**********
#set ($takenBold = ${lead.mktotakenBold})
#set ($eligibleBold = ${lead.mktoeligiblebold})
#if (($eligibleBold.equals("1")) && ($takenBold.equals("")))
#set ($showBold = 25000)
#else
#set ($showBold = 0)
#end
##******************Eligible or Taken Juno**********
#set ($takenJuno = ${lead.mktotakenJuno})
#set ($eligibleJuno = ${lead.mktoeligiblejuno})
#if (($eligibleJuno.equals("1")) && ($takenJuno.equals("")))
#set ($showJuno = 2500)
#else
#set ($showJuno = 0)
#end
##******************Eligible or Taken Niche**********
#set ($takenNiche = ${lead.mktotakenNiche})
#set ($eligibleNiche = ${lead.mktoeligibleniche})
#if (($scpMember.equals("Coreg Not a Member")) && ($coReg.equals("niche")))
#set ($showNiche = 0)
#elseif (($eligibleNiche.equals("")) && ($coReg.equals("campusreel")) && ($takenNiche.equals("")))
#set ($showNiche = 2000)
#elseif (($eligibleNiche.equals("1")) && ($takenNiche.equals("")))
#set ($showNiche = 2000)
#else
#set ($showNiche = 0)
#end
##******************Eligible or Taken Christian Connector**********
#set ($takenCC = ${lead.mktotakenChristianConnector})
#set ($eligibleCC = ${lead.mktoeligiblechristianc})
#if (($eligibleCC.equals("1")) && ($takenCC.equals("")))
#set ($showCC = 2500)
#else
#set ($showCC = 0)
#end
##******************Eligible or Taken Nitro**********
#set ($takenNitro = ${lead.mktotakenNitro})
#set ($eligibleNitro = ${lead.mktoeligiblenitro})
#if (($eligibleNitro.equals("1")) && ($takenNitro.equals("")))
#set ($showNitro = 2000)
#else
#set ($showNitro = 0)
#end
##Adding up the dollars available
#set ($subtotal = $math.add($showNiche, $showBold, $showNitro, $showCC, $showJuno, 13000))
#set ($formattedTotal = $number.format("number", $subtotal))
=?UTF-8?Q?${esc.d}?=${formattedTotal}
Well, it makes sense that the Q-encoding shows up, since that’s the literal output and it has no special meaning in the body, only in the Subject. But you probably can take out the Q-encoding as it wasn’t the cause/solution — the cause is all the literal whitespace.
Got it. Thanks Sanford.
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
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.
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.