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

Parse Server Simple Mailgun Adapter 'verifyUserEmails' issue

我正在使用 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 解析服务器配置如下:

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 适配器无论如何都不起作用。任何帮助将不胜感激。谢谢!

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

看看: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。

使用 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!');
});

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

appName: 'yourAppName',