在Parse服务器中有一个节点mailgun模块。这是我的代码:
var mailgun = require('mailgun-js');
var mg = mailgun.client({username: 'myApi', key: process.env.MAILGUN_API_KEY || 'myKey'});
mg.messages.create('myUrl', {
from: "myEmail@example.com",
to: "email@example.com",
subject: "Test",
text: "Test"
})
.then(msg => console.log(msg)) // logs response data
.catch(err => console.log(err)); // logs any error
但控制台告诉我这个:
error: Uncaught internal server error. [TypeError: mailgun.client is not a function] TypeError: mailgun.client is not a function
由于
答案 0 :(得分:3)
看起来需要初始化mailgun-js模块并使用不同的方式:
var api_key = 'key-XXXXXXXXXXXXXXXXXXXXXXX';
var domain = 'mydomain.mailgun.org';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
var data = {
from: 'Excited User <me@samples.mailgun.org>',
to: 'serobnic@mail.ru',
subject: 'Hello',
text: 'Testing some Mailgun awesomness!'
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});