parse.com - How can I read a local file in Cloud Code as a string? -
i'm using parse cloud code.
my system has welcome message. use mailgun send it.
the problem have message html file, let html file in server, read using cloud code , pass info mailgun.
can read local text file using cloud code , have in program string?
should save file in public folder or in same folder cloudcode program?
i'm not confident mailgun, believe should work mailchimp or mandrill. if so, should able store on mailgun whole html template , have template_vars complete.
this sample code of our own way send mail html mandrill system
parse.cloud.define("sendmailtemplate", function(request, response) { var emails = request.params.emails; var template_name = request.params.template_name; var template_merge_content = request.params.template_merge_content; var subject = request.params.subject; var mandrill = require('cloud/mandrilltemplatesend.js'); if (subject === undefined) { subject = 'mail sent mandrill'; body = subject; } parse.config.get().then(function(config) { mandrill.initialize(config.get('mandrill_key')); }).then(function() { _.each(emails, function(email) { mandrill.sendtemplate({ template_name: template_name, template_content: [{ name: template_merge_content.username, content: '' }], message: { text: '', subject: subject, from_email: 'contact@yourdomain.com', to: [{ email: email, name: template_merge_content.username }], merge_vars: [{ rcpt: email, vars: template_merge_content }], }, async: false }); }); }).then(function() { response.success('success'); }, function(error) { response.error(error); }); }); this object template_merge_content quiet important. it's object saved dynamic vars send complete html mail.
according http://blog.mailgun.com/transactional-html-email-templates/ seems have same kind of method send mail.
so final advice not store html template within parse's class, or save within https://parse.com/docs/js/api/symbols/parse.config.html
Comments
Post a Comment