对于 Meteor 1.0.5,使用
Template.<yourTemplate>.onCreated(function() { ... })
而不是
Template.<yourTemplate>.created = ...
在Meteor #20: Verify an Email with Meteor Accounts 的第 4 步中。
下面的演示在 Meteor 1.0.5 下运行良好。
验证电子邮件.html:
<head>
<title>Verify Email</title>
</head>
<body>
<h1>Sending Email Demo</h1>
{{> loginButtons}}
</body>
verifyEmail.js:(为您的案例替换用户、密码和服务器值)
if (Meteor.isClient) {
Template.SendAnyEmail.onCreated(function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message = 'Verify email link expired [403]') {
console.log('Sorry this verification link has expired.')
}
} else {
console.log('Thank you! Your email address has been confirmed.')
}
});
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
smtp = {
username: 'user@example.com',
password: 'password',
server: 'mail.example.com',
port: 465
};
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) + ':' + smtp.port;
Accounts.emailTemplates = {
from: 'Administrator <user@example.com>',
siteName: 'YourSite',
verifyEmail: {
subject: function(user) {
return 'Verification email from Example.com';
},
text: function(user, url) {
return 'Hi,\n' +
'Please open the link below to verify your account on Example.com:\n' + url;
}
}
};
});
Accounts.onCreateUser(function(options, user) {
Meteor.setTimeout(function() {
Accounts.sendVerificationEmail(user._id);
}, 2 * 1000);
return user;
});
}