Table of Contents

Bulk send an email

Short example of sending email via bulk link.

using Mailtrap;
using Mailtrap.Emails.Requests;
using Mailtrap.Emails.Responses;

try
{
    var apiToken = "<API-TOKEN>";
    using var mailtrapClientFactory = new MailtrapClientFactory(apiToken);
    IMailtrapClient mailtrapClient = mailtrapClientFactory.CreateClient();
    SendEmailRequest request = SendEmailRequest
        .Create()
        .From("hello@demomailtrap.co", "Mailtrap Test")
        .To("world@demomailtrap.co")
        .Subject("You are awesome!")
        .Category("Integration Test")
        .Text("Congrats for sending test email with Mailtrap!");
    SendEmailResponse? response = await mailtrapClient
        .Bulk()
        .Send(request);
}
catch (Exception ex)
{
    Console.WriteLine("An error occurred while sending email: {0}", ex);
}
Caution

Examples in this article could contain API token specified as a plain text in code or configuration files.
This is not a recommended approach and is used only for brevity.

In production scenarios it is highly recommended to use more secure approaches to store sensitive configuration, such as: