Extends Verify to enable snapshotting of emails via EmailPreviewServices.
The purpose of this project is provide faster feedback when using code to generate html emails.
EmailPreviewServices is a paid service, an account is required to get an API key.
See Milestones for release notes.
Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.
Call VerifyEmailPreviewServices.Initialize at test startup.
[ModuleInitializer]
public static void Init() =>
VerifyEmailPreviewServices.Initialize();The default behavior is to use an environment variable named EmailPreviewServicesApiKey for the API key.
An explicit API key can be used:
[ModuleInitializer]
public static void Init() =>
VerifyEmailPreviewServices.Initialize("ApiKey");Assume the code under test produces the following html email.
static string html =
"""
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Email</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px;">
<div style="max-width: 600px; margin: 0 auto; background-color: white; padding: 20px; border-radius: 10px;">
<h1 style="color: #333;">Welcome to Our Service!</h1>
<p style="color: #666; line-height: 1.6;">
This is a test email to demonstrate the email preview functionality.
</p>
<a href="https://"
style="display: inline-block; padding: 10px 20px; background-color: #007bff;
color: white; text-decoration: none; border-radius: 5px; margin-top: 10px;">
Get Started
</a>
</div>
</body>
</html>
""";[Test]
[Explicit]
public async Task GeneratePreview()
{
var preview = new EmailPreview
{
Html = html,
Devices =
[
Device.OutlookWebDarkModeChrome,
Device.iPhone13
]
};
await Verify(preview);
}Generating previews takes in the range of tens of seconds. The time take can vary based on the number and type of email devices selected. For example:
- Generating a a single device (GmailFirefox) takes ~20sec.
- Generating previews for 5 devices (OutlookWebChrome, Outlook2019, Outlook2016, iPhone13, and GmailFirefox) takes ~25sec.
While this may seem slow compared to other tests, it is orders of magnitude faster than having to test previews manually. It is also less error prone than manual testing
Execution will timeout after 6min and throw an exception.
Splitting individual devices, or groups of devices, over multiple tests can be used to have more control of when previews are generated and achieve faster feedback.
Tests that execute in the 10s of seconds range can significantly slow down a test run. As such it is recommended that email preview tests are configured to be explicit in Debug mode.
[Test]
#if DEBUG
[Explicit]
#endif
public async Task GeneratePreview()
{
var preview = new EmailPreview
{
Html = html,
Devices = [Device.Outlook2019]
};
await Verify(preview);
}This way developer can opt in to manually run specific previews, and on the build server previews test will allways be executed.
Preview pane designed by M. Oki Orlando from The Noun Project.


