Skip to content

About

A .NET client for the whole [SMTP2GO](https://www.smtp2go.com/) v3 API

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Scott.Mail.Smtp2Go

NuGet Target frameworks API coverage Dependabot Downloads ci License: LGPL-3.0-or-later

A .NET client for the whole SMTP2GO v3 API: sending (JSON, MIME, batch, scheduled), webhooks, reporting and statistics, templates, suppressions, allowed senders and recipients, API keys, SMTP users, domains, subaccounts, email archiving and SMS. Targets netstandard2.0, net8.0 and net10.0, is trim- and AOT-compatible, sends the API key in a header rather than the body, surfaces the API's own error payloads as typed exceptions, and ships opt-in packages for Microsoft.Extensions.DependencyInjection and ASP.NET Core webhook endpoints.

Features

  • The whole v3 API, typed. 69 of 69 documented operations across 18 families, each with request and response records, reachable as client.Email, client.Webhooks, client.Stats, client.Activity, client.Templates, client.Suppressions, client.Archive, client.ApiKeys, client.SmtpUsers, client.IpAuth, client.Domains, client.SingleSenders, client.AllowedSenders, client.AllowedRecipients, client.Subaccounts, client.DedicatedIps and client.Sms. client.Raw reaches anything the API adds before the library does, with the same authentication, routing, validation and error mapping.
  • Current sending features. fastaccept, schedule with scheduled-email search and removal, email/batch, URL-sourced attachments, templates without a subject, EnsureAccepted() to turn a 200 with failed recipients into an exception.
  • Authentication and routing. The key goes in the X-Smtp2go-Api-Key header or as Authorization: Bearer; never in the body. Region (US, EU, AU) selects the regional endpoint, SubaccountId is merged into every call of an endpoint that documents it, and both can be overridden per call.
  • Errors you can act on. Smtp2GoApiException carries the API's error_code, error, request_id and field_validation_errors; Smtp2GoRateLimitException parses Retry-After. Documented limits (50 MB under email/*, 1 MB elsewhere, 100 recipients per field) fail client-side before a byte is sent.
  • Resilience that matches the docs. Retry only on idempotent endpoints (or when a call opts in), per-endpoint rate-limit classes for the limits SMTP2GO documents (60/min activity/search, 5/min api_keys/add, 50/hour subaccount/add), circuit breaker and timeouts through Microsoft.Extensions.Http.Resilience.
  • Webhooks end to end. Managing webhooks, parsing JSON and form-encoded callbacks into typed events (unknown fields land in Extra, custom headers in CustomHeaders), and MapSmtp2GoWebhook for ASP.NET Core with bearer or basic authentication, a source-IP allow-list and IWebhookEventHandler<TEvent> dispatch from the concrete event up to WebhookEvent.
  • Paging and the archive. IAsyncEnumerable<T> pagers over activity, templates, suppressions, subaccounts and the archive; downloading the original archived message.
  • Observability. An ActivitySource span per call, a Meter with request, duration and email-result instruments, and source-generated logging with stable event ids.
  • Built to last. netstandard2.0, net8.0 and net10.0; trim- and AOT-compatible with source-generated JSON; the public API tracked with PublicAPI.*.txt and package validation against the previous release; the API reference harvested weekly into docs/api-spec/, with contract tests that fail when the models and the documentation disagree.

Install

dotnet package add Scott.Mail.Smtp2Go

Optional: Scott.Mail.Smtp2Go.DependencyInjection (options, IHttpClientFactory, resilience) and Scott.Mail.Smtp2Go.AspNetCore (MapSmtp2GoWebhook).

Quick start

using Scott.Mail.Smtp2Go;

var client = new Smtp2GoClient(apiKey: "api-...");

var response = await client.Email.SendAsync(new EmailSendRequest
{
    Sender = "Alice <alice@example.com>",
    To = ["bob@example.com"],
    Subject = "Hello from Scott.Mail.Smtp2Go",
    TextBody = "It works.",
});

Console.WriteLine($"Sent: {response.Data.Succeeded} succeeded, {response.Data.Failed} failed ({response.RequestId})");

The quick start above is compiled by a unit test so it stays in sync with the API.

Documentation

Start with Getting started, then pick what you need:

Document Covers
Sending email JSON, MIME and batch sends, fastaccept, scheduling, attachments, templates, EnsureAccepted()
Webhooks Managing webhooks, parsing callbacks, receiving them in ASP.NET Core
Reporting Statistics, quota, activity search and paging
Archive Searching archived email and downloading the original message
Account management and SMS API keys, SMTP users, domains, senders, allowed lists, subaccounts, dedicated IPs, SMS
Configuration Client options, regions, authentication, dependency injection, resilience
Observability Logging, metrics and tracing
Errors The exception types and how API responses map to them
API coverage Every SMTP2GO endpoint and the client member that calls it
API notes Where the live API and its documentation disagree
Contributing Building, testing and releasing

Runnable examples are in demo/: a send, archive search and download round trip, a generic host with dependency injection, and a webhook receiver. Release history is in the changelog.

Security

See SECURITY.md for how to report a vulnerability.

License

LGPL-3.0-or-later

About

A .NET client for the whole [SMTP2GO](https://www.smtp2go.com/) v3 API

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages