Log In

This guide helps to setup SMTP2GO with .NET. This library provides a simple way to send email via the SMTP2GO API and also access other endpoints in the API in a standard way.

Advanced setup options, including setting your preferred IOC API connection and using Email Template features, can be found at the GitHub repository.

Step 1

Add a reference to the latest Nuget package:

dotnet add package Smtp2Go.ApiClient


Install-Package Smtp2Go.ApiClient

Step 2

Create an Smtp2GoApiService providing your Smtp2Go API key:

var service = new Smtp2GoApiService("api-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

Step 3

Create an EmailMessage object to send

var message = new EmailMessage("From Name ", "To Name ", "alsoto@address.email");

message.BodyHtml = "Email HTML Body";
message.BodyText = "Email Plain Text Body";

message.AddToAddress("anotherto@address.email", "Another To Name");
message.AddCcAddress("ccto@address.email", "Cc To Name");

Step 4

Optional: add base64 encoded or local file system file attachments to the email:

message.AddAttachment("attachment_name.txt", "base64_attachment_data", "text/plain");
message.AddAttachment("C:\\a_word_document.docx", "application/msword");

Step 5

Optional: add base64 encoded or local file system file inline images to the email:

message.AddInlineImage("image_name.png", "base64_inline_image_data", "image/png");
message.AddInlineImage("C:\\image_file.png", "image/png");

Step 6

Optional: add custom email headers:

message.AddCustomHeader("Reply-To", "Reply To Name ");

Step 7

Send the email using the API service’s async SendEmail method. Response information will contain success and failure information along with any other identifiers returned from the Smpt2Go API.

var response = await service.SendEmail(message);

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.