CM.EmailGateway 1.1.0

dotnet add package CM.EmailGateway --version 1.1.0
                    
NuGet\Install-Package CM.EmailGateway -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CM.EmailGateway" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CM.EmailGateway" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="CM.EmailGateway" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CM.EmailGateway --version 1.1.0
                    
#r "nuget: CM.EmailGateway, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CM.EmailGateway@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CM.EmailGateway&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=CM.EmailGateway&version=1.1.0
                    
Install as a Cake Tool

CM Email Gateway .NET SDK

A .NET SDK for integrating with the CM Email Gateway API, providing a simple and robust way to send marketing and transactional emails.

.NET Version License

Installation

NuGet Package

dotnet add package CM.EmailGateway

Manual Installation

Clone the repository and build the project:

git clone https://github.com/cmdotcom/email-gateway-api-sdk.git
cd email-gateway-api-sdk/dotnet
dotnet build

Quick Start

Basic Marketing Email

using CM.Email.GateWayApi.SDK;
using CM.Email.GateWayApi.SDK.Exceptions;

// Initialize the client
var client = new EmailGatewayClient("YOUR_PRODUCT_TOKEN", sandboxMode: true);

// Prepare email request as JSON
var jsonRequest = """
{
    "from": {
        "email": "sender@example.com",
        "name": "Marketing Team"
    },
    "to": [
        {
            "email": "recipient@example.com",
            "name": "John Doe"
        }
    ],
    "subject": "Welcome to our service!",
    "html": "<html><body><h1>Welcome!</h1></body></html>",
    "text": "Welcome to our service!"
}
""";

try
{
    var response = await client.SendMarketingEmailAsync(jsonRequest);
    Console.WriteLine($"Email sent! MessageId: {response.MessageId}");
}
catch (EmailGatewayException ex)
{
    Console.WriteLine($"Error: {ex.Message} (Status: {ex.StatusCode})");
}

Transactional Email with Priority

var jsonRequest = """
{
    "from": {
        "email": "noreply@example.com",
        "name": "System Notifications"
    },
    "to": [
        {
            "email": "user@example.com",
            "name": "User Name"
        }
    ],
    "subject": "Your Order Confirmation",
    "html": "<h1>Order Confirmed</h1>",
    "customerReference": "ORDER-12345"
}
""";

// Send with high priority
var response = await client.SendTransactionalEmailAsync(jsonRequest, "high");

EmailGatewayClient

Constructor
public EmailGatewayClient(string ProductToken, bool SandboxMode = false, string? BaseUrlOverride = null)

Parameters:

  • ProductToken (string, required): Your CM Email Gateway product token
  • SandboxMode (bool, optional): Enable sandbox mode for testing (default: false)
  • BaseUrlOverride (string, optional): Custom base URL for the API endpoint (default: "https://api.cm.com/email/gateway")
Methods
SendMarketingEmailAsync
public async Task<EmailResponse> SendMarketingEmailAsync(string jsonRequest)

Sends a marketing email.

Parameters:

  • jsonRequest (string): JSON string containing the email request

Returns: Task<EmailResponse>

Throws: EmailGatewayException

SendTransactionalEmailAsync
public async Task<EmailResponse> SendTransactionalEmailAsync(string jsonRequest, string priority)

Sends a transactional email with specified priority.

Parameters:

  • jsonRequest (string): JSON string containing the email request
  • priority (string): Priority level - "high", "normal", or "low"

Returns: Task<EmailResponse>

Throws: EmailGatewayException

Email Request Structure

EmailRequest JSON Schema

{
    "from": {
        "email": "sender@example.com",
        "name": "Sender Name"
    },
    "replyTo": {
        "email": "reply@example.com",
        "name": "Reply Name"
    },
    "to": [
        {
            "email": "recipient@example.com",
            "name": "Recipient Name"
        }
    ],
    "cc": [
        {
            "email": "cc@example.com",
            "name": "CC Name"
        }
    ],
    "bcc": [
        {
            "email": "bcc@example.com",
            "name": "BCC Name"
        }
    ],
    "subject": "Email Subject",
    "html": "<html><body>HTML content</body></html>",
    "text": "Plain text content",
    "attachments": [
        {
            "filename": "document.pdf",
            "content": "base64EncodedContent",
            "contentType": "application/pdf",
            "contentId": "unique-id"
        }
    ],
    "customerReference": "YOUR-REFERENCE-ID"
}

Response Structure

EmailResponse

public class EmailResponse
{
    public int Status { get; set; }
    public string Message { get; set; }
    public bool Success { get; set; }
    public string MessageId { get; set; }
}

Example Success Response:

{
    "status": 200,
    "message": "Email sent successfully",
    "success": true,
    "messageId": "abc123-def456-ghi789"
}

Configuration

Sandbox Mode

Enable sandbox mode for testing without sending real emails:

var client = new EmailGatewayClient("YOUR_TOKEN", sandboxMode: true);

Custom Base URL

Override the default API endpoint if you need to use a different environment:

var client = new EmailGatewayClient(
    "YOUR_TOKEN", 
    sandboxMode: false, 
    baseUrlOverride: "https://custom-api.example.com/email/gateway"
);

The default base URL is https://api.cm.com/email/gateway.

Priority Levels

For transactional emails, three priority levels are available:

  • high: Urgent emails
  • normal: Standard transactional emails
  • low: Non-urgent notifications

Requirements

  • .NET 8.0 or later
  • Valid CM Email Gateway product token

Dependencies

  • Microsoft.Extensions.Http (>= 8.0.0)
  • System.Text.Json (>= 8.0.5)

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 99 4/1/2026
1.0.1 106 3/17/2026
1.0.0 86 3/17/2026