Promact.EmailService.SendGrid 3.0.0

dotnet add package Promact.EmailService.SendGrid --version 3.0.0
                    
NuGet\Install-Package Promact.EmailService.SendGrid -Version 3.0.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="Promact.EmailService.SendGrid" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Promact.EmailService.SendGrid" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Promact.EmailService.SendGrid" />
                    
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 Promact.EmailService.SendGrid --version 3.0.0
                    
#r "nuget: Promact.EmailService.SendGrid, 3.0.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 Promact.EmailService.SendGrid@3.0.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=Promact.EmailService.SendGrid&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Promact.EmailService.SendGrid&version=3.0.0
                    
Install as a Cake Tool

EmailService

Generic Email service implementation for sending emails via different Email providers (SES, SendGrid,SMTP,Azure etc.)

Usage

IEmailService, Email, EmailAddress, AttachmentData, and TemplatedEmailRequest all live in the Promact.EmailService namespace (the core package).

using Promact.EmailService;

private IEmailService _emailService;

public async Task MyMethod()
{
    // The email which we are using should be verified in Service Provider whichever you are using (SES, SendGrid,SMTP etc.)
    //In Case Of Azure Your EmailDomain Should be Verified And Connected To Your  Email Communications Services

    var email = new Email(
        to: new List<EmailAddress>
        {
            new EmailAddress("xyz@domain.com", "Receiver Name"),
            new EmailAddress("lmn@domain.com", "Receiver Name")
        },
        from: new EmailAddress("abc@pqr.com", "Sender Name"),
        cc: new List<EmailAddress>
        {
            new EmailAddress("xyz1@domain.com", "Receiver Name"),
            new EmailAddress("lmn1@domain.com", "Receiver Name")
        },
        bcc: new List<EmailAddress>
        {
            new EmailAddress("xyz2@domain.com", "Receiver Name"),
            new EmailAddress("lmn2@domain.com", "Receiver Name")
        },
        subject: "Test subject",
        body: "Test body",
        isBodyHtml: true
    );

    // Add attachments. You can Attach Multiple Attachment
    email.Attachments.Add(new AttachmentData(
        content: System.IO.File.ReadAllBytes("path/to/file.txt"),
        fileName: "FileName",
        contentType: "FileType"
    ));

    await _emailService.SendEmailAsync(email);
}

public async Task SendTemplatedEmail()
{
    var templatedEmailRequest = new TemplatedEmailRequest(
        to: new List<EmailAddress>
        {
            new EmailAddress("xyz@domain.com", "Receiver Name"),
            new EmailAddress("lmn@domain.com", "Receiver Name")
        },
        from: new EmailAddress("abc@pqr.com", "Sender Name"),
        cc: new List<EmailAddress>
        {
            new EmailAddress("xyz1@domain.com", "Receiver Name"),
            new EmailAddress("lmn1@domain.com", "Receiver Name")
        },
        bcc: new List<EmailAddress>
        {
            new EmailAddress("xyz2@domain.com", "Receiver Name"),
            new EmailAddress("lmn2@domain.com", "Receiver Name")
        },
        templateNameOrId: "TemplateID", // Replace with your actual template name or ID
        templateData: new { name = "Value1" }, // Replace with your actual template data            
        subject: "Subject"
    );

    // Add attachments
    templatedEmailRequest.Attachments.Add(new AttachmentData(
        content: System.IO.File.ReadAllBytes("path/to/file.txt"),
        fileName: "FileName",
        contentType: "FileType"
    ));

    await _emailService.SendTemplatedEmailAsync(templatedEmailRequest);
}

SES

Add nuget package

Promact.EmailService.SES

ASP.NET Core projects

Add below in Startup.cs inside ConfigureServices method

services.AddSESEmailService(options =>
{
    options.AccessKeyId = Configuration.GetSection("AWS:AccessKeyId").Value;
    options.SecretAccessKey = Configuration.GetSection("AWS:SecretAccessKey").Value;
    options.Region = Configuration.GetSection("AWS:Region").Value;
});

Add relevant appsettings.json values

"AWS": {
    "AccessKeyID": "",
    "SecretAccessKey": "",
    "Region":  ""
}

Inject IEmailService in class constructor from where you want to send emails

public MyClass(IEmailService emailService)
{
...
}

Console or other type of applications

Create new object of SESEmailService passing relevant configuration values

var emailService = new SESEmailService(new SESOptions(){ });

SendGrid

Add nuget package

Promact.EmailService.SendGrid

ASP.NET Core projects

Add below in Startup.cs inside ConfigureServices method

services.AddSendGridEmailService(options =>
{
    options.APIKey = Configuration.GetSection("SendGrid:APIKey").Value;
});

Add relevant appsettings.json values

"SendGrid": {
    "APIKey": ""
}

Inject IEmailService in class constructor from where you want to send emails

public MyClass(IEmailService emailService)
{
...
}

Console or other type of applications

Create new object of SendGridEmailService passing relevant configuration values

var emailService = new SendGridEmailService(new SendGridOptions(){ });

SMTP

Add nuget package

Promact.EmailService.SMTPS

ASP.NET Core projects

Add below in Startup.cs inside ConfigureServices method

 services.AddSMTPEmailService(options =>
 {
     options.Host = configuration.GetSection("SMTP:Host").Value;
     options.Port = int.Parse(configuration.GetSection("SMTP:Port").Value);
     options.UserName = configuration.GetSection("SMTP:UserName").Value;
     options.Password = configuration.GetSection("SMTP:Password").Value;
 });

Add relevant appsettings.json values

"SMTP": {
  "Host": "",
  "Port":,
  "UserName": "",
  "Password": ""
}

Inject IEmailService in class constructor from where you want to send emails

public MyClass(IEmailService emailService)
{
...
}

Console or other type of applications

Create new object of SMTPEmailService passing relevant configuration values

var emailService = new SMTPEmailService(new SMTPOptions(){ });

Azure

Add nuget package

Promact.EmailService.Azure

ASP.NET Core projects

Add below in Startup.cs inside ConfigureServices method

services.AddAzureEmailService(options =>
{
    options.ConnectionString= Configuration.GetSection("Azure:ConnectionString").Value;
});

Add relevant appsettings.json values

// You can get your connection string From Azure Portal in  Your Communication Service > Setting > Keys.
"Azure": {
  "ConnectionString": ""
},

Inject IEmailService in class constructor from where you want to send emails

public MyClass(IEmailService emailService)
{
...
}

Console or other type of applications

Create new object of AzureEmailService passing relevant configuration values

var emailService = new AzureEmailService(new AzureOptions(){ });
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
3.0.0 92 7/25/2026
2.0.0 92 7/25/2026
2.0.0-beta-1.0.0 160 2/16/2024
1.0.1 741 10/5/2020
1.0.0 604 10/5/2020