Page 1 of 1
Email Template $baseurl and $from not working
Posted: Fri Apr 06, 2012 3:00 am
by pokemon007
I saw blServerInfo that holds server info (serverName, serverPort) is passed into MessageCreator as one of the params in additionalConfigItems. I tried to use $serverName and $serverPort, but they are not replaced. Then saw $baseurl was used in OOTB templates, but it doesn't work either. Neither does $from. Following is a segment of my template:
<a href="http://${baseurl}/account/activate/${token}">http://$baseurl/account/activate/$token</a>
Email: <a href="mailto:${from}">${from}</a><br>
Am I missing something?
Thank you!
Re: Email Template $baseurl and $from not working
Posted: Mon Apr 09, 2012 11:41 pm
by bpolster
The additionalAttributes get copied to the map that is being rendered by the velocity template.
The following should work for you:
${serverInfo.serverName}
${serverInfo.serverPort}
You can add additional attributes that will be available to your templates by adding props to the call to EmailService:
Code: Select all
EmailService.sendTemplateEmail(EmailTarget emailTarget, EmailInfo emailInfo, HashMap<String, Object> props)
$from, and $baseUrl appear to be from legacy code. I didn't see anyway in the existing code base that those could get populated. I've opened a bug to cleanup the sample "vm" files included with the project.
Re: Email Template $baseurl and $from not working
Posted: Wed Apr 11, 2012 6:02 pm
by pokemon007
Thank you, Brian, for your reply. You are right, I'm still using 1.5 code and haven't sync'ed up with latest code.
We'll try to use $serverInfo.serverName and $serverInfo.ServerPort. Do you have a substitute key for $from?
Without $baseurl it does have a minor problem, we'll always need to feed the template with the port even if it's default 80. Or we have to do some tweak such as moving the separator colon (:) as part of port such that the template can use them like:
<a href="http://${serverInfo.serverName}${serverInfo.serverPort}/account/activate/${token}">http://${serverInfo.serverName}${serverInfo.serverPort}/account/activate/$token</a>
For the server that has default port the configuration will be like:
serverInfo.serverName=mycompany.com
serverInfo.serverNamePort=
and for those that have non-default port such as 8080, configuration will be like:
serverInfo.serverName=mycompany.com
serverInfo.serverNamePort=:8080
But this may cause confusion error prune.
Appreciate it!
Re: Email Template $baseurl and $from not working
Posted: Wed Apr 11, 2012 6:05 pm
by pokemon007
Forgot to mention, the reason I want to use the built-in $from or equivalent key is that send_from is maintained in ServerInfo module and I prefer other top modules shouldn't need to maintain this info.
Thank you!