我正在尝试在注册时向用户发送验证邮件。我使用angular作为前端,使用nodejs、mongoDb和环回作为后端。这是我的html注册表。
<form class="form-signin" name="frm" role="form" accept-charset="UTF-8" novalidate>
<fieldset>
<input type="email" name="email" id="email" ng-model="profile.email" required>
<input type="submit" ng-submit value="Sign Up" ng-click="register()">
</fieldset>
</form>
下面是寄存器控制器中的代码
$scope.register = function() {
$scope.profile.createTS = new Date();
$scope.profile.username = $scope.profile.email;
$scope.profile.id = uuid.v4();
$scope.profile.created = new Date();
$scope.profile.lastUpdated = new Date();
AppUser.create($scope.profile,function() {
$location.path('/login');
}
};
我在datacourses.json 中添加了这些细节
"emailDs": {
"name": "emailDs",
"connector": "mail",
"transports": [{
"type": "smtp",
"host": "n1plcpnl0010.prod.ams1.secureserver.net",
"secure": true,
"port": 465,
"tls": {
"rejectUnauthorized": false
},
"auth": {
"user":"support@mycompany.com",
"pass": "password"
}
}]
}
我在app-user.js 中添加了以下代码
AppUser.afterRemote('create', function(context, AppUser) {
console.log('> AppUser.afterRemote triggered');
var options = {
type: 'email',
to: AppUser.email,
from: 'support@mycompany.com',
subject: 'Thanks for registering.',
template: path.resolve(__dirname, '../../../telekha-web/app/views/login.html'),
redirect: 'http://172.17.0.1:9000/login',
user: AppUser
};
AppUser.verify(options, function(err, response) {
if (err) {
next(err);
return;
}
console.log('> verification email sent:', response);
context.res.render('response', {
title: 'Signed up successfully',
content: 'Please check your email and click on the verification link ' +
'before logging in.',
redirectTo: 'http://172.17.0.1:9000/login',
redirectToLinkText: 'Log in'
});
});
});
用户可以使用此代码进行注册。但是,验证邮件并没有发送给用户。我需要在我的视图中添加什么吗?我还在model-config.js 中添加了电子邮件实例
请帮忙!!
我使用了以下设置:
model-config.json
"Email":{
"dataSource":"Email"
}
datasources.json
"Email": {
"name": "email",
"defaultForType": "mail",
"connector": "mail",
"transports": [
{
"type": "SMTP",
"host": "abc.com",
"secureConnection": true,
"port": 587,
"auth": {
"user": "mail@abc.com",
"pass": "pass"
}
}
]
}
需要指出两件事:
1) 尝试在datasources.json中使用port 587
2) 尝试在数据源中使用"Email"
作为模型和的名称。(代替emailDs
)
我可以通过这种方式从本地服务器发送电子邮件(使用hMailServer和本教程:https://www.hmailserver.com/documentation/latest/?page=howto_set_up_local)