我希望在创建一些用户时发送的确认电子邮件。 我使用这些账户密码包,因此任何会计方法被称为在我的代码。
我的文档,我需要调用read:
Accounts.sendVerificationEmail(userId, [email])
但问题是,我不知道什么时候调用它。
我试着在回调函数来调用Accounts.onCreateUser(func)
但用户并没有在数据库中尚未创建。
有任何想法吗?
我希望在创建一些用户时发送的确认电子邮件。 我使用这些账户密码包,因此任何会计方法被称为在我的代码。
我的文档,我需要调用read:
Accounts.sendVerificationEmail(userId, [email])
但问题是,我不知道什么时候调用它。
我试着在回调函数来调用Accounts.onCreateUser(func)
但用户并没有在数据库中尚未创建。
有任何想法吗?
在服务器端:
Accounts.config({sendVerificationEmail: true, forbidClientAccountCreation: false});
得到了上述评论的答案。
sendVerificationEmail
仅提供服务器端 。 我最常做的是使用setInterval
内onCreateUser
等待流星发送电子邮件之前创建的用户。
阅读更多 : 确认与流星帐户的电子邮件 。
// (server-side)
Accounts.onCreateUser(function(options, user) {
user.profile = {};
// we wait for Meteor to create the user before sending an email
Meteor.setTimeout(function() {
Accounts.sendVerificationEmail(user._id);
}, 2 * 1000);
return user;
});
你需要在环境变量指定的邮件。 然后使用Accounts.sendVerificationEmail(userId, [email])
中的回调Account.onCreateUser
遗憾的错误和延迟。
像这样(下面是完整的例子js文件):
Template.register.events({
'submit #register-form' : function(e, t) {
e.preventDefault();
var email = t.find('#account-email').value
, password = t.find('#account-password').value;
// Trim and validate the input
Accounts.onCreateUser({email: email, password : password}, function(err){
if (err) {
// Inform the user that account creation failed
} else {
// Success. Account has been created and the user
// has logged in successfully.
Accounts.sendVerificationEmail(this.userId, email);
}
});
return false;
} });
if(Meteor.isServer){
Meteor.startup(function(){
process.env.MAIL_URL='smtp://your_mail:your_password@host:port'
}
}
我refered这个网页: http://blog.benmcmahen.com/post/41741539120/building-a-customized-accounts-ui-for-meteor
http://sendgrid.com/blog/send-email-meteor-sendgrid/
为什么我的帐户包没有发送确认电子邮件流星应用程序?