解析服务器中的mailgun模块(不是适配器)

时间:2016-05-08 18:39:47

标签: javascript node.js parse-platform mailgun 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

由于

1 个答案:

答案 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);
});

此处的文档:https://www.npmjs.com/package/mailgun-js