CovenirBPO.Packages.SendgridNotificationSystem
1.1.0
dotnet add package CovenirBPO.Packages.SendgridNotificationSystem --version 1.1.0
NuGet\Install-Package CovenirBPO.Packages.SendgridNotificationSystem -Version 1.1.0
<PackageReference Include="CovenirBPO.Packages.SendgridNotificationSystem" Version="1.1.0" />
paket add CovenirBPO.Packages.SendgridNotificationSystem --version 1.1.0
#r "nuget: CovenirBPO.Packages.SendgridNotificationSystem, 1.1.0"
// Install CovenirBPO.Packages.SendgridNotificationSystem as a Cake Addin #addin nuget:?package=CovenirBPO.Packages.SendgridNotificationSystem&version=1.1.0 // Install CovenirBPO.Packages.SendgridNotificationSystem as a Cake Tool #tool nuget:?package=CovenirBPO.Packages.SendgridNotificationSystem&version=1.1.0
Sendgrid Notification Library
For Covenir Integration
2024-01-23 Updated: 2024-05-01
Install the library
Install Nuget package CovenirBPO.Packages.SendgridNotificationSystem
Createing a native IEmailNotificationContent object
In your project solution, create an object that inherits the IEmailNotificationContent interface.
This object will contain the required properties that the notification system will utilize when sending notification emails.
using SendgridNotificationSystem.Lib;
namespace SendgridNotificationSystem.Testing;
internal class EmailNotificationContent : IEmailNotificationContent
{
public List<string> RecipientAddresses { get; set; } = new List<string>();
public string Subject { get; set; } = string.Empty;
public string BodyContent { get; set; } = string.Empty;
public void AddRecipientAddress(string recipientAddress)
{
RecipientAddresses.Add(recipientAddress);
}
public void RemoveRecipientAddress(string recipientAddress)
{
for (int i = 0; i < RecipientAddresses.Count; i++)
{
if (RecipientAddresses[i]== recipientAddress)
{
RecipientAddresses.RemoveAt(i);
break;
}
}
}
}
Set an environment variable
Create a local environment variable on the machine that will be sending notifications:
Key | Value |
---|---|
SENDGRID_API | Your Sendgrid API key |
Add Recipients
In the calling assembly, create a new EmailNotificationContent object.
var content = new EmailNotificationContent
{
Subject = "Subject of Email",
BodyContent = "Body of the email"
TemplateID = "Your Sendgrid Template ID" // Optional for text only emails, required for template-based emails
};
content.AddRecipientAddress("receiver@email.com");
Call the service
using SendgridNotificationSystem;
. . .
// This will produce a basic text-only email.
public async Task SendEmail(IEmailNotificationContent content)
{
await new Lib.SendgridNotificationSystem()
.SendSendgridEmailAsync(content);
}
. . .
or
. . .
// This will allow dynamically fill the custom template with the same Email notification content
public async Task SendEmailWithTemplate(IEmailNotificationContent content)
{
await new Lib.SendgridNotificationSystem()
.SendSendgridTemplateEmailAsync(content);
})
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- SendGrid (>= 9.29.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CovenirBPO.Packages.SendgridNotificationSystem:
Package | Downloads |
---|---|
CovenirBPO.Packages.PreprocessorCommon
A common core library for Covenir's preprocessor workflow. |
GitHub repositories
This package is not used by any popular GitHub repositories.
BREAKING CHANGE: Added Template ID to IEmailNotificationContent to support the new SendSendgridTemplateEmailAsync method.
NOTE: This will require changes to any existing implementations of IEmailNotificationContent.
NOTE: The IEmailNotificationContent object can be passed to both standard text-based email methods and the new template-based email method.
The template-based email method will pull fields from the IEmailNotificationContent object and populate the template with the values.
Added additional documentation.