解析服务器简单的Mailgun适配器' verifyUserEmails'问题

时间:2016-05-08 01:00:58

标签: heroku mailgun parse-server

我正在使用Parse Server Simple Mailgun Adapter,而我的Parse Server在Heroku上完美运行。我是node.js和Express的新手,但我通过以下方式在Parse Server的根目录上安装了适配器:

npm i parse-server-simple-mailgun-adapter

这创建了一个node_modules文件夹,并基本上克隆了Mailgun适配器的Github存储库。我的index.js Parse Server配置如下所示:

var api = new ParseServer({
  verifyUserEmails: true,
  databaseURI: databaseUri || 'mongodb://DATABASE',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'APPID',
  masterKey: process.env.MASTER_KEY || 'MASTERKEY', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'https://SERVER/parse',  // Don't forget to change to https if needed
  publicServerURL: 'https://SERVER/parse',
  fileKey: process.env.FILE_KEY || 'FILEKEY',
  push: {
    ios: [
      {
        pfx: 'FILE.p12', // Dev PFX or P12
        bundleId: 'BUNDLE',
        production: false // Dev
      },
      {
        pfx: 'FILE.p12', // Prod PFX or P12
        bundleId: 'BUNDLE',  
        production: true // Prod
      }
    ]
  },
  emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      fromAddress: 'EMAIL@DOMAIN',
      domain: 'DOMAIN',
      apiKey: 'KEY',
    }
  },
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});

注释掉verifyUserEmails密钥时,服务器可以正常工作。有了它,服务器将无法正常工作。 Mailgun适配器无论如何都不起作用。任何帮助将不胜感激。谢谢!

2 个答案:

答案 0 :(得分:4)

您是否设置了电子邮件适配器?

看看:https://github.com/ParsePlatform/parse-server

电子邮件验证和密码重置

验证用户电子邮件地址并通过电子邮件重置密码需要电子邮件适配器。作为parse-server软件包的一部分,我们提供了一个通过Mailgun发送电子邮件的适配器。要使用它,请注册Mailgun,并将其添加到初始化代码中:

var server = ParseServer({
  ...otherOptions,
  // Enable email verification
  verifyUserEmails: true,
  // The public URL of your app.
  // This will appear in the link that is used to verify email addresses and reset passwords.
  // Set the mount path as it is in serverURL
  publicServerURL: 'https://example.com/parse',
  // Your apps name. This will appear in the subject and body of the emails that are sent.
  appName: 'Parse App',
  // The email adapter
  emailAdapter: {
    module: 'parse-server-simple-mailgun-adapter',
    options: {
      // The address that your emails come from
      fromAddress: 'parse@example.com',
      // Your domain from mailgun.com
      domain: 'example.com',
      // Your API key from mailgun.com
      apiKey: 'key-mykey',
    }
  }
});

您还可以使用社区提供的其他电子邮件适配器,例如parse-server-sendgrid-adapter或parse-server-mandrill-adapter。

OR

使用mailgun-js在云代码中创建自己的代码 https://www.npmjs.com/package/mailgun-js

var api_key = '[SECRET_API_KEY]';
var domain = '[DOMAIN_HERE]';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

Parse.Cloud.define('testemail', function(req, res) {
  var data = {
    from: 'Excited User <me@samples.mailgun.org>',
    to: 'foo@bar.com',
    subject: 'Hello',
    text: 'Testing some Mailgun awesomness!'
  };

  mailgun.messages().send(data, function (error, body) {
    console.log(body);
  });

  res.success('Email Sent!');
});

答案 1 :(得分:0)

发生这种情况的真正原因是因为您需要在服务器初始化中包含appName(这使我疯狂了数小时)

appName: 'yourAppName',