Skip to content

Email

Email is a universal tool for communicating with your users. From welcoming new sign-ups to sending critical notifications and beautiful newsletters, a reliable email system is a cornerstone of a modern application. However, building one that is robust, scalable, and doesn’t slow down your application can be tricky.

SliceFlow tackles this challenge with a sophisticated, asynchronous email system designed for both power and reliability.

The Problem with Sending Email Directly

Imagine a user signs up for your application. Your code needs to create their account in the database and then send them a welcome email. If you try to send the email directly during the sign-up process, you introduce a potential bottleneck. What if your email server is slow or temporarily unavailable? The user is stuck waiting, staring at a loading spinner, for the email to send. This creates a poor user experience and makes your application feel sluggish.

SliceFlow’s Solution: The Asynchronous Post Office

To solve this, SliceFlow treats email like a real-world post office. Instead of trying to deliver the mail itself, your application simply drops a letter into a mailbox. A dedicated, background postal worker then comes along, picks up the mail, and handles the delivery.

This “mailbox” is a high-speed message queue (powered by RabbitMQ), and the “postal workers” are dedicated background services. This asynchronous approach has several key advantages:

  • It’s Fast: Your application can “send” an email in a fraction of a second, because all it’s doing is quickly placing a message in a queue. The user gets an immediate response.
  • It’s Reliable: If the email server is down, the message simply waits safely in the queue. The background worker will automatically retry sending it later, ensuring no emails are lost.
  • It’s Scalable: If you suddenly need to send thousands of emails, the system can handle it without breaking a sweat. The queue will absorb the load, and you can even add more background workers to process the emails faster.

Two Flavors of Email: Simple and Powerful

SliceFlow’s email system is built on the excellent FluentEmail library and offers two ways to send emails, catering to different needs.

1. Simple Emails

For straightforward notifications, plain text messages, or emails with basic HTML, the SimpleEmailMessage is perfect. You provide the recipient, subject, and the body of the email, and SliceFlow takes care of the rest.

var simpleEmail = new SimpleEmailMessage
{
Recipient = "user@example.com",
Subject = "Your account has been updated",
Body = "Just a quick note to let you know that your profile information has been successfully updated."
};
// Drop the "letter" into the mailbox
await messageService.PublishAsync(QueueEnum.EmailNotifications, simpleEmail);

2. Template-Based Emails

For richer, more complex emails like order confirmations or newsletters, you’ll want to use templates. SliceFlow leverages the power of the Razor engine—the same technology used to build web pages in ASP.NET—to create beautiful, dynamic email templates.

This allows you to:

  • Separate content from design: Keep your email logic clean and your templates organized.
  • Use dynamic data: Easily insert user-specific information, like a customer’s name or a list of products they ordered.
  • Create reusable layouts: Ensure all your emails have a consistent, professional look and feel.

Sending a template-based email is just as easy:

var templateEmail = new TemplateEmailMessage
{
Recipient = "customer@example.com",
Subject = "Your Order Confirmation",
Template = EmailTemplate.OrderConfirmation, // The name of your Razor template
Model = new OrderEmailModel { ... } // The data to use in the template
};
await messageService.PublishAsync(QueueEnum.EmailNotifications, templateEmail);

Full Control and Easy Configuration

Getting started is as simple as adding ConfigureEmailServices() to your Program.cs and filling in your SMTP server details in appsettings.json.

For development and testing, SliceFlow includes thoughtful features like a global “off switch” to prevent accidental emails to real users, and an override that redirects all outgoing emails to a single address of your choice.

While SliceFlow can work with any SMTP provider, for production environments, we highly recommend Amazon Web Services (AWS) Simple Email Service (SES). It offers an excellent balance of reliability and cost-effectiveness.

  • High Deliverability: AWS has a strong reputation with internet service providers, helping your emails land in the inbox, not the spam folder.
  • Extremely Cost-Effective: With a generous free tier and a pay-as-you-go model, SES is often significantly cheaper than other email service providers.
  • Scalable and Reliable: Built on AWS’s robust infrastructure, it’s designed to handle email volumes of any size.

Setting up SES is straightforward, and you can plug its SMTP credentials directly into SliceFlow’s appsettings.json.

By combining a powerful templating engine with a resilient, asynchronous delivery system, SliceFlow provides a complete and professional solution for all your application’s email needs.