Sending Purchase Receipts
Learn how to send an email with Meteorjs.
We'll cover the following...
After we’ve confirmed the Stripe payment and updated the records in the database, the next thing we can do is send the user a receipt detailing their payment. To send an HTML-based email from the server, we need an HTML template in which we’ll dynamically replace values with placeholders. The email will be sent on the server, so the template we use should be processed on the server-side.
Blaze template on the server
The template to use is stored in the private
folder. Remember that the private
folder can only be accessed by server-side code. Open the private/email-templates/sendReceipt.html
file. This file is an HTML Blaze template file.
Blaze is the Meteor framework default rendering engine used to dynamically display data in front-end applications.
Take a look inside the file and notice that some code is written inside double curly brackets ({{ }}
). These are template tags that are replaced with dynamic content when the file is compiled. Take a look at lines 279–286, and notice the following code: {{#each booksBought}}
.
The booksBought
variable is an array. To loop through all books, the {{#each }}
template function is used. We loop through the booksBought
variable and display the ...