【问题标题】:Parse Server Simple Mailgun Adapter 'verifyUserEmails' issue解析服务器简单 Mailgun 适配器“verifyUserEmails”问题
【发布时间】:2016-05-08 01:00:57
【问题描述】:

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

【问题讨论】:

    标签: heroku mailgun parse-server


    【解决方案1】:

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

    看看: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!');
    });
    

    【讨论】:

    • 问题是验证后它需要一些时间才能工作。我的原始消息中的代码在稍后尝试后有效。
    【解决方案2】:

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

    appName: 'yourAppName',

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      • 2018-01-23
      • 2011-10-03
      • 1970-01-01
      • 2017-02-14
      相关资源
      最近更新 更多