解析服务器简单邮件枪适配器'verifyUserEmails'问题



我使用的是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

电子邮件验证和密码重置

验证用户电子邮件地址并通过电子邮件启用密码重置需要电子邮件适配器。作为解析服务器包的一部分,我们提供了一个适配器,用于通过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',
    }
  }
});

您还可以使用社区提供的其他电子邮件适配器,如解析服务器sendgrid适配器或解析服务器mandrill适配器。

使用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',

最新更新