Meteorjs Accounts.config sendVerificationEmail 选项没有任何效果

Meteorjs Accounts.config sendVerificationEmail option doesn't have any effect

我正在创建没有 accounts.ui 包的帐户,只有 accounts-base/accounts-password。我在 server

有一个代码
Accounts.config({
  sendVerificationEmail: true,
  forbidClientAccountCreation: true // cause we call it from server code
});

然后在注册表提交后我打电话给

Accounts.createUser({User account document where `email` field is set to actual email}); 

它创建用户(我可以稍后使用该用户登录)没有问题或错误,除了它不向我发送任何电子邮件消息。

我安装了 meteor 电子邮件包,但我没有配置电子邮件 URL,所以它应该在标准输出中打印消息,但这并没有发生。

我可以使用 post user create hook 并手动发送电子邮件,但我想它应该可以在没有文档中描述的额外工作的情况下工作。

Meteor 版本为 1.0.3.1

按照此分步操作应该可以让您开始:

https://gentlenode.com/journal/meteor-20-verify-an-email-with-meteor-accounts/42

我面临同样的问题,但它适用于我的另一个项目。 有一个解决方法是使用挂钩 (https://github.com/Meteor-Community-Packages/meteor-collection-hooks)。

添加meteor add matb33:collection-hooks

的包

然后在服务器端导入import { CollectionHooks } from 'meteor/matb33:collection-hooks';

最后,在您的 Meteor.starup 中您可以添加以下代码:

Meteor.users.after.insert((userId, doc) => {
    Accounts.sendVerificationEmail(doc._id);
});

我也试过在 Accounts.onCreateUser 上发送电子邮件验证,但是,用户似乎还没有存储在数据库中,因此失败了。

使用 Meteor 1.8.3.

更新:阅读代码后我发现只有当用户在客户端注册时sendVerificationEmail才有效(这不是你的情况,也不是我的情况,因为我们俩禁止它)。

您可以检查 account_commons.js 并检查他们是否对此有评论:

// - sendVerificationEmail {Boolean}
//     Send email address verification emails to new users created from
//     client signups.

现在您可以安心地继续使用您的钩子了。