Portal email template error

Hi

I have set up sending of email with basic auth username and password upon request approval. I tested it and it worked with a custom email templates. I then added custom style to portal pages and added email footer template, only making changes in the portal/ directory (custom css, images, fonts, modified pages). After that it stopped sending out the basic auth email to user (still sent the “request approved” email to admin address). Dashboard (v1.3.0.14) logged out:

Mar 24 11:15:23 graph-api tyk-analytics[26696]: time="Mar 24 11:15:23" level=error msg="HTML Template error: html/template:basic_auth_key_approved.txt:3:12: no such template \"emailStyles\""

I removed the “{{ template “emailStyles” . }}” from the basic auth template’s .html and .txt file and it logged:

Mar 23 15:09:24 graph-api tyk-analytics[13150]: time="Mar 23 15:09:24" level=error msg="HTML Template error: template: basic_auth_key_approved.txt:8:29: executing \"BasicAuthKeyApproved\" at <.Data.Username>: can't evaluate field Data in type *main.ComboData"

I have reverted the style changes but it still gives the same errors.
What could be causing this? What more could I try since reverting the changes? Also, why are there two, .html and .txt, files for a template?

Tarmo

Hi @Tarmo,

Did you edit the styles.html file in that folder? If so, could you please make sure it still contains the {{ define "emailStyles" }} line (and that the email template you’re working on still contains {{ template "emailStyles" . }})? These allow the template to refer to the underlying Go code in the Dashboard which is very important for its functionality. In case you’re unsure, the styles.html page should take on this format:

{{ define "emailStyles" }}
  {{ if .Styles }}
    <style>
      {{ .Styles|safeCSS }}
    </style>
  {{ end }}
{{ end }}

Also, we provide two different formats for the email templates to cater to recipients who can only view plaintext emails. Many mailers provide the two options.

Kind regards,
Jess @ Tyk

I didn’t edit that file and it contains the code you wrote. Also the templates contain {{ template “emailStyles” . }}).

Hi @Tarmo,

And just to confirm, you haven’t deleted or moved the basic_auth_key_approved.txt file from the portal/email_templates folder? Also, are you able to confirm that you’ve configured your email settings in the tyk_analytics.conf file in the manner described by this link. If so, are you able to attach the contents of the plaintext email template to this thread so that we can investigate further?

Kind regards,
Jess @ Tyk

Yes I haven’t deleted or moved the template and I have proper configuration that I have tested that it works with the default template.

Since last time I have been troubleshooting this issue in VM and found it’s a problem with encoding. I made the custom template .txt file with Sublime Text 2 which by default saves the .txt files with Windows 1252 encoding. Unfortunately, it seems to break dashboard’s ability to read email templates when I replaced the original file.
Also, it’s not able to recover after I delete that Windows 1252 file and put back a UTF-8 encoded one. It will still give the same error. I had to run “apt-get remove tyk-dashboard” and reinstall to get the automatic email to work again.

So in summary, the customized content had nothing to do with it. I can reproduce this error by simply saving the default (without customization) .txt template with Windows 1252 encoding. Doing this to the .html file doesn’t cause this error.

Is there a way I can get it working again without uninstalling and reinstalling?

Correction: This happens even if I save the the txt file with UTF-8. If I edit the original file it in place in VM it works fine, even using “ä” and “&auml;”.

Putting back the default file without saving it in any other encoding seems to fix it. But then I’m not able to overwrite that with ansible without breaking it.

Hi @Tarmo,

We noticed that the .txt files you sent also contained the {{ template "emailStyles" . }} line which I asked you to add earlier. If you look at the default templates set up in the email_templates folder, you’ll probably find that this line appears in the .html version of the file and not in the .txt version as plaintext emails aren’t set up to use any of the CSS added to the stylesheet. Have you tried removing that line from the file and saving it in UTF-8 format in the portal/email_templates folder (you may need to restart the Dashboard after you’ve made any changes)? If so, could you let me know if that fixes the issue?

Apologies for giving seemingly contradictory advice on this ealier as that’s probably confused matters. Just to reiterate, the "emailStyles" stylesheet needs to be referred to in the HTML templates but not in the plaintext ones.

Kind regards,
Jess @ Tyk

Also probably worth noting, the plaintext files should have .txt extension and shouldn’t contain any markup in them. The HTML templates need to have a .html extension instead and can contain markup as well as embedded templates, &c.

Yeah, the fault was on our end. We assumed they had the same content and didn’t notice that txt file doesn’t have the emailStyles and it has “{{.Username}}” instead of “{{.Data.Username}}”.
It works now. Thank you!

Hi Jess,

i want to send the welcome email to my registered user, how can i implement that?

Amazone ses is used in my project , here are what i am do:
1.
“code”: “amazonses”,
“settings”: {
“Endpoint”: “Endpoint”,
“AccessKeyId”: “*",
“SecretAccessKey”: "

}
in tyk_analytics.conf

2.“monitor”: {
“enable_trigger_monitors”: true,
“configuration”: {
“method”: “POST”,
“target_path”: “http://posttestserver.com/post.php?dir=tyk-monitor-drop”,
“template_path”: “templates/monitor_template.json”,
“header_map”: {“x-tyk-monitor-secret”: “12345”},
“event_timeout”: 10
},
“global_trigger_limit”: 80.0,
“monitor_user_keys”: false,
“monitor_org_keys”: true
}
in tyk.conf, but not clear target_path mean.

It would be appreciate if you cloud send me the guide on how to send the welcome email more clearly.

Thanks,
Moon

Hi,

The webhooks documentation here goes into more detail of how to configure that section the config.

hello Josh,

thanks for your quick response.

can you share me any guide about email configuration? do you mean first i need to config a webhood? Is that all the config that i dont need any other config??

I think that is the case. The configuration section of the monitor section you add to the config is just a webhook.

Hi Josh,
So do i still need the configuration in the tyk.conf and tyk_analytics.conf???

Hi Josh,

would you explain more about the email setting, any other config need ??

Thanks,
Moon