I am currently working on a project where I need to send emails to every individual in an array. To achieve this, I require the email address of each person. I have a collection called Benutzer/benutzer which includes the name and email address of each person.
Below is the code snippet from the client side:
Template.NeuesEvent.onCreated(function() {
this.subscribe('events');
this.subscribe('friends');
this.subscribe('benutzer');
});
Template.NeuesEvent.events({
"submit .add-event": function(event){
var Name = event.target.name.value;
var Beschreibung = event.target.beschreibung.value;
var Datum = event.target.Datum.value;
var Autor = Meteor.userId();
var eingeladene = []; <-- this is the array
$.each($('.FreundeCheckbox:checked'), function(){
eingeladene.push($(this).val());
});
var email = Meteor.Benutzer.findOne({"email": eingeladene});<<------
<<---- here i want to grab the email adress
if (Name == "")
{
confirm("Das Event braucht einen Namen ;)")
}
else {
Meteor.call('addEvent', Name, Beschreibung, Datum, eingeladene, Autor, email) <<--
<<------and paste the information here
event.target.name.value = "";
event.target.beschreibung.value = "";
FlowRouter.go('/meineEvents');
return false;
}
}
});
This part of my method.js does not contain the email function yet, but I am aware of how to implement it:
Meteor.methods({
addEvent(Name, Beschreibung, Datum, eingeladene, Autor, email) {
Events.insert({
Name: Name,
Beschreibung: Beschreibung,
erstelltAm: new Date(),
Datum: Datum,
Eingeladen: eingeladene,
Autor: Autor
});
SSR.compileTemplate('InviteEmail', Assets.getText('Invite-Email.html'));
var emailData = {
Name: Name,
Beschreibung: Beschreibung,
erstelltAm: new Date(),
Datum: Datum,
Eingeladen: eingeladene,
Autor: Autor
};
Email.send({
to: email, <<<-----everytime a new one
from: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="117469707c617d7451747c70787d3f727e7c">[email protected]</a>",
subject: "Einladung",
html: SSR.render('InviteEmail', emailData),
});
}
});
Now that you understand my objective, please assist me with two challenges - obtaining the email addresses and iterating over the `Email.send` function for each email address.