Hi there - I am trying to send an email in cloud code using mailgun, but am struggling to get it working!
I have added the function to my index.js
var client = require('cloud/myMailModule-1.0.0');
client.initialize('xxxxx', 'xxx');
Parse.Cloud.define("sendEmailToUser", function(request, response) {
client.sendEmail({
from: "MyM...@CloudCode.com",
subject: "Hello from Cloud Code!",
text: "Using Parse and My Mail Module is great!"
}).then(function(httpResponse) {
response.success("Email sent!");
}, function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
});
});
And added the module in myMailModule-1.0.0
(function() {
var domain = 'xxxxxxx';
var key = 'xxxxxxxxx';
module.exports = {
initialize: function(domainName, apiKey) {
domain = domainName;
key = apiKey;
return this;
},
sendEmail: function(params, options) {
return Parse.Cloud.httpRequest({
method: "POST",
url: "
https://api:" + key + "@" + url + "/" + domain + "/messages",
body: params,
}).then(function(httpResponse) {
if (options && options.success) {
options.success(httpResponse);
}
}, function(httpResponse) {
if (options && options.error) {
options.error(httpResponse);
}
});
}
}
}());
HOWEVER, I am getting the following error message: Error: Cannot find module 'cloud/myMailModule-1.0.0'] code: 'MODULE_NOT_FOUND' }
Any suggestions would be much appreciated!! Thanks