Open chris-aeviator opened 8 years ago
The mail enpdoint accepts any data, as long as it contains to
(email) and name
: https://github.com/nametacker/node-templater-mailer-microservice/blob/a71a240a4e1d227581902d83ff500cd012f7d97e/api.js#L148 so you might be doing something wrong.
Can you show me your templates and the data you send?
atob
is not implemented in Node.js, you need to define it:
if (!atob) {
var atob = function (str) {
return new Buffer(str, 'base64').toString('binary')
}
}
Thanks for your very quick response 👍
Initially I was trying to submit a JSON object like
var x = {"to":"christopher@mydomain.cc","name":"Chris Test","email":"test@test.cc","order_details":{"items":[{"product":"Die Bodenstandige","price":69.99,"qty":1}]}};
and output it in the template with <%= order_details %>
but it does not reach the template as the server responds with unexpected token i
(coming from the "items" string ) .
Thanks for your hint with atob
I ws not aware that such a simple Javascript function is not implemented in node.js :)
What's your template?
By now I'm just trying to output the json into the template, but what I want in the end is to create a HTML structure out of the ( JSON.parse 'ed data).
curl -v -X PUT http://server.xyz:3200/templates/projectOrder \ -H 'Content-Type: application/vnd.node-templater-mailer-microservice.v1+json; charset=utf-8' \ --data '{"subject":"Neue Bestellung von <%= name %>","html":"Toll, <%= name %> hat was bei uns bestellt! <h3>Der xxx geht an:</h3> <p>email: <%= email %></p><h3>Diese xxx verlassen uns:<%= order_details %><h3/><p>"}'
Hi…I decided to put the direct sending of the JSON data aside and tried to implement the atob way as it fit's my needs.
Still I cannot get the server/templating engine to accept atob
.
I tried the following things:
if (!atob) { var atob = function (str) { return new Buffer(str, 'base64').toString('binary') } }
into api.js
, config.js
and main.js
api.js
config.js
and main.js
via var atob = require('atob')
atob
to https://github.com/nametacker/node-templater-mailer-microservice/blob/master/main.js#L35Still in my template the field is processed with <%= atob(user_details) %>
where user details is defined on the browsersite with var user_details = btoa(JSON.stringify(userDetails));
Inside the .js files I'm able to process a atob() command - it log's out perfectly to the console!
Can you please give me a hint where I need to define atob
to be recognized by your module?
Thanks for your great work, I like to use the microservice alot for different projects that do not require a backend but recent notifications.
To use the microservice for data-driven applications it would be benefitial if the user could payload some json data into the mail, as the underlying lodash library supports this.
I could not find out a way to transport e.g. a json object into the mailer (also html structure and "pure" data objects (just displayed as
[object]
) fail with unexpected token responses). Further attempts in base64 encoding the object failed, as i getatob is undefined
response from the server after i saved<%= atob(value) %>
to the template.I would appreciate any help and would be willing in contributing.