Utilities
Renderer
Rendering Emails with BlazorEmail
Once you have set up your email component and configured your parameters using EmailParameterCollectionBuilder<TEmail>
, you can render the email using the BlazorEmailRenderer
. This section outlines how to do this in detail.
Step-by-Step Rendering Process
- Instantiate the Email Renderer: Ensure that you have an instance of
BlazorEmailRenderer
ready to use. You typically do this in your service or context where you handle email operations.
- Configure Your Email Parameters: Use the
EmailParameterCollectionBuilder<TEmail>
to set the parameters for your email. This is done through a lambda expression, allowing you to specify which properties of your email template you want to populate.
- Render the Email: Use the
RenderEmail
method of theBlazorEmailRenderer
to render the email template with the specified parameters. This method is asynchronous and will return the rendered HTML as a string.
- Send the Email: After rendering the email, you can proceed to send it through your email service or SMTP client.
Example Code
Here’s a complete example demonstrating the entire flow from building parameters to rendering and sending the email: