lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
https://lukelowrey.com/dotnet-email-guide-2021/
MIT License
3.04k stars 438 forks source link

Capturing the rendered email body #340

Open jovball opened 2 years ago

jovball commented 2 years ago

I have a business case for capturing the rendered email body. Is that possible with FluentEmail? I am using Razor templates if that makes any difference.

DavidDeSloovere commented 2 years ago

You can create a decorator for the mail sender and check the content there.

/// <summary>
/// Decorator for <c>FluentEmail.Core.Interfaces.ISender</c>.
/// </summary>
public class CustomMailSender : ISender
{
    ...
}

I use Autofac to register the decorator. builder.RegisterDecorator<CustomMailSender, ISender>();

This is independent of the type of mail sender you are actually using (smtp, sendgrid...).

For more info, I would suggest stackoverflow or discussions here.