Just starting out with Meteor.
I'm working on sending an email notification to new users who are invited to join the service. I want the email content to be personalized with details of the user who sent the invitation. Here is the code snippet I have:
Meteor.publish('profile', function() {
return Meteor.users.find(this.userId);
});
var emailData = {
existingUser: 'currentUser().profile.displayName',
existingOrganisation: 'currentUser().profile.organisation',
existingEmail: Meteor.users.emails[0].address
};
//Customizing enrollment email content as per Meteor Docs example
Accounts.emailTemplates.siteName = "Amendd";
Accounts.emailTemplates.from = "Amendd <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e9e8aaf5e2f7ebfec7e6e9e3efeaacffe4e8ea">[email protected]</a>>";
Accounts.emailTemplates.enrollAccount.subject = function (user) {
return "Welcome to Amendd";
};
Accounts.emailTemplates.enrollAccount.html = function (user, url) {
return SSR.render('enrollAccountEmail', emailData) + url;
};
In my '/private' folder, I have a separate file called enrollAccount.html where the content for enrollment email is stored. The focus right now is on fixing the email field issue, hence placeholders after existingUser and existingOrganisation variables.
Upon saving and running the project in Terminal, I encounter the following error message:
TypeError: Cannot read property '0' of undefined"
This points to the [0] position in the existingEmail variable.
Any insights on how to resolve this problem would be greatly appreciated!
UPDATE
The solution involved reorganizing the emailData object within the function:
SSR.compileTemplate('enrollAccountEmail', Assets.getText('enrollAccountEmail.html'));
Accounts.emailTemplates.siteName = "Amendd";
Accounts.emailTemplates.from = "Amendd <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84eaeba9f6e1f4e8fdc4e5e9e1eae0e0aaebe8e1">[email protected]</a>>";
Accounts.emailTemplates.enrollAccount.subject = function (user) {
return "Welcome to Amendd , " + user.email;
};
Accounts.emailTemplates.enrollAccount.html = function (user, url) {
var emailData = {
existingUser: Meteor.user().profile.displayName,
existingOrganisation: Meteor.user().profile.organisation,
existingEmail: Meteor.user().emails[0].address
};
return SSR.render('enrollAccountEmail', emailData) + url;
};