DEV Community

Bervianto Leo Pratama
Bervianto Leo Pratama

Posted on

Testing Your Email Sending in .NET with Ethereal


For the previous part, you may need to visit the post here.

Alright, let's get started from scratch. Firstly, I will generate my project. Secondly, I will give a simple example code to send emails using SMTP server. Lastly, I will add the repository link, and you can test the code.

Note: You will need to create the Ethereal Account first. If you want to create an account, please visit here.



Please make sure you have .NET SDK Installation. Don't have it yet? Download here. Anyway, I use .NET 6.

Create .NET Project

  1. Generate the project using this command: dotnet new console -o MailExample.
  2. I also generate .gitignore and sln files. Using these commands: dotnet new gitignore and dotnet new sln. After that connect sln file with the project file, using this command: dotnet sln add .\MailExample\.
  3. Finally, try to build your project using dotnet build.

Coding Time

  1. Update MailExample/Program.cs file.
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Text;
using System.Text.Json;

var smtpClient = new SmtpClient("")
    Port = 587,
    Credentials = new NetworkCredential("<update your username here>", "<update your user here>"),
    EnableSsl = true,

var attachment = Attachment.CreateAttachmentFromString(JsonSerializer.Serialize(new
    Message = "Hello World!"
}), "helloworld.json", Encoding.UTF8, MediaTypeNames.Application.Json);

var message = new MailMessage("", "")
    Subject = "Test Email! Hello World!",
    Body = "<p>Test Email</p><b>Hello World!</b>",
    IsBodyHtml = true,


catch (SmtpException ex)
Enter fullscreen mode Exit fullscreen mode
  1. Run the project. Using this command: dotnet run --project .\MailExample\.

  2. Check your account inbox (the Ethereal account, not your To inbox).




.NET Email Example

Some Notes

  • Anyway, I have little concern about privacy. So, if you have private projects, I don't recommend using this. I recommend using this if you have a public personal project or another project that it's okay if you disclose the information.
  • For the alternative, you may use Mailtrap or other email testing providers.

Thank you

Thanks for reading.


Top comments (5)

kaylumah profile image
Max Hamulyák

I used for similar effect in the past.

berviantoleo profile image
Bervianto Leo Pratama

Thank you for the reference. 👍

dracheal profile image

That's true, you need to see feedback, you need to follow the statistics, you need to make sure that your email marketing efforts are not for nothing. For instance, I can tell you that responsive email templates are great email tools for marketing, and many entrepreneurs actively use it to effectively build brand awareness, so it's important to keep in mind as well.