You can use CSharp's built in SMTP client package . Let us use XUnit and the MailSlurp client to create an email address and send emails to it.

How does it work?

First add the package to your CSharp project

Configure your MailSlurp API Key with the email client:

Then you can create inboxes during tests or in your application to connect to SMTP:

Example XUnit tests

Using XUnit you can connect to SMTP mailboxes during tests and send and receive emails.

Other use cases

You can use to send emails in DotNET but what if you want to receive emails instead? Use MailSlurps email webhooks to have emails sent directly to your server.

Receive emails by polling

You can use the waitFor methods with the MailSlurp SDK client. You can receive emails using waitFor methods on the WaitForControllerApi class.

A common use case for temporary SMTP mailboxes in Csharp is verifying OTP 2FA login during integration testing. OTP one-time passwords are ephemeral codes that can be sent to a user's email address when they want to access a web application or mobile app.

See the OTP testing guide for more information.