MujahidHtmlEmailHelper 1.0.5
dotnet add package MujahidHtmlEmailHelper --version 1.0.5
NuGet\Install-Package MujahidHtmlEmailHelper -Version 1.0.5
<PackageReference Include="MujahidHtmlEmailHelper" Version="1.0.5" />
paket add MujahidHtmlEmailHelper --version 1.0.5
#r "nuget: MujahidHtmlEmailHelper, 1.0.5"
// Install MujahidHtmlEmailHelper as a Cake Addin
#addin nuget:?package=MujahidHtmlEmailHelper&version=1.0.5
// Install MujahidHtmlEmailHelper as a Cake Tool
#tool nuget:?package=MujahidHtmlEmailHelper&version=1.0.5
Introduction
This package is usefull for sending HTML email by reading and replacing content from HTML file.
How to start?
Follow below these steps to send your first email using
Html File
. You can also send usingHtml String
, but we're focussing onHtml File
methode here.1 Install :
MujahidHtmlEmailHelper
from NuGetInstall package by running command in vs package manager console:
Install-Package MujahidHtmlEmailHelper -Version 1.0.5
OR By searching in NuGet Package Manager in VS.2 Create Html Template File
Here we're creating
Welcome.html
for example. And adding tag[CustomerName]
which will be replaced leter.<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <h1>Welcome [CustomerName]!</h1> </body> </html>
3 Implement class
EmailTemplateFields
- Create class in your project with any name, I'm using
EmailTemplates
. - Implement class comming from namespace
MujahidHtmlEmailHelper
- And Create method for template file, I'm using
Welcome
forWelcome.html
using System; using System.Collections.Generic; using System.Text; using MujahidHtmlEmailHelper; namespace EmailHelperByMujahid { public class EmailTemplates : EmailTemplateFields { //Method for Welcome.html template public static IEmailTemplateFields Welcome(string customerName) { var fields = new Dictionary<string, string>(); fields.Add("[CustomerName]", customerName); //[CustomerName] will be replaced with customerName in Welcome.html document. return EmailTemplate("Welcome.html", fields); //EmailTemplate method comming from EmailTemplateFields. } } }
4 Implementation
Here we're sending email using
SendGrid
you can also useSmtpClient
.using System; using MujahidHtmlEmailHelper; namespace EmailHelperByMujahid { class Program { static void Main(string[] args) { //Initialize email fields var emailFields = new EmailFields( subject: "your subject", to: "mujahidatwork@gmail.com", emailTemplateFields : EmailTemplates.Welcome("Muhammad Mujahid") ); //Sending email using SendGrid var response = emailFields.SendEmail(new SendGridOptions() { ApiKey="YOUR SEND GRID API KEY", Email= "FROM EMAIL", Name= "FROM NAME" }); } } }
5 Result
- Create class in your project with any name, I'm using
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- SendGrid (>= 9.21.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.