Meteor 将Robomongo链接到自动电子邮件发送服务?
我有一个运行在meteor.js和mongo.db上的应用程序。我正在使用robomongo作为mongo.db的工具。现在我想做以下几点: 1.有人向我的服务注册,向数据库添加电子邮件 2.我想给那个人发送一封自动欢迎邮件Meteor 将Robomongo链接到自动电子邮件发送服务?,meteor,Meteor,我有一个运行在meteor.js和mongo.db上的应用程序。我正在使用robomongo作为mongo.db的工具。现在我想做以下几点: 1.有人向我的服务注册,向数据库添加电子邮件 2.我想给那个人发送一封自动欢迎邮件 有没有可能怎么做 您需要一个电子邮件服务器SMTP,然后使用。如果您没有电子邮件服务器,也不想创建电子邮件服务器,请使用商业解决方案 您可以在这里找到完整的工作示例: 请注意,它会在Meteor应用程序中创建新用户,但当您使用Robomongo或任何其他方式更新MongoD
有没有可能怎么做 您需要一个电子邮件服务器SMTP,然后使用。如果您没有电子邮件服务器,也不想创建电子邮件服务器,请使用商业解决方案 您可以在这里找到完整的工作示例: 请注意,它会在Meteor应用程序中创建新用户,但当您使用Robomongo或任何其他方式更新MongoDB时,也会产生相同的效果 首先安装软件包电子邮件,以便能够使用Email.send。 在下面的示例中,我假设向collection Meteor.users添加新用户时,应该发送邀请电子邮件。 以非常相似的方式,您可以检测电子邮件是否已添加到用户对象 user.emails.length已更改,然后发送电子邮件 然后看看代码:
// SERVER SIDE CODE:
Meteor.startup(function () {
// clean users on app resetart
// Meteor.users.remove({});
if(Meteor.users.find().count() === 0){
console.log("Create users");
Accounts.createUser({
username:"userA",
email:"userA@example.com",
profile:{
invitationEmailSend:false
}
}) ;
Accounts.createUser({
username:"userB",
email:"userB@example.com",
profile:{
invitationEmailSend:false
}
})
}
Meteor.users.find().observe({
added:function(user){
console.log(user.username, user.profile.invitationEmailSend)
if(!user.profile.invitationEmailSend){
Email.send({
from: "from@mailinator.com",
to: user.emails[0].address,
subject: "Welcome",
text: "Welcome !"
});
// set flag 'invitationEmailSend' to true, so email won't be send twice in the future ( ex. during restart of app)
Meteor.users.update({_id:user._id},{$set:{"profile.invitationEmailSend":true}});
}
}
})
});
上述代码将向profile.invitationEmailSend中标志不等于true的用户发送电子邮件。发送电子邮件后,服务器更新数据库中的用户文档,并将user.profile.invitationEmailSend设置为true
无论何时使用Robomongo或任何其他方式向mongoDB添加用户,都会执行添加的功能,并且只向新用户发送电子邮件