Skip to content
Flávio da Maia Jr edited this page Jun 29, 2022 · 2 revisions

📬 Welcome to the Mailtrap wiki!

Mailtrap for .NET

👨‍💻 How to use

Add package

It's possible to add using .NET CLI or Package Manager.

.NET CLI

dotnet add package Mailtrap

Package Manager

PM> Install-Package Mailtrap

Check other alternatives on NuGet.org

ℹ️ Requirements for new devs

Before starting your tests using Mailtrap you need to create an account on Mailtrap.io

🤓 Let's code

Text only

using Mailtrap.Source.Models;

var mailtrap = new MailtrapSender("your username", "your password");

var email = new Email(
    "to@mailtrap.io",
    "from@mailtrap.io",
    "Sending e-mail test using Mailtrap for .NET 📬",
    "Ahoooy! It really works! 😎");

mailtrap.Send(email);

HTML on body

using Mailtrap.Source.Models;

var mailtrap = new MailtrapSender("your username", "your password");

var body = "<html>" +
           "<head>" +
           "<title>Mailtrap for .NET</title>" +
           "</head>" +
           "<body>" +
           "<h1>Ahoooy!</h1>" +
           "<p>It really works using HTML templates as well! 😎<p>" +
           "<p>Unleash your creativity<p>" +
           "</body>" +
           "</html>";

var email = new Email(
    "to@mailtrap.io",
    "from@mailtrap.io",
    "Sending e-mail test using Mailtrap for .NET 📬", 
    body,
    isBodyHtml: true);

mailtrap.Send(email);