Parse Server 中的 mailgun 模块(不是适配器)

mailgun module (not adapter) in Parse Server

在 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

谢谢

看来 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);
});

文档在这里:https://www.npmjs.com/package/mailgun-js