MujahidHtmlEmailHelper 1.0.5

dotnet add package MujahidHtmlEmailHelper --version 1.0.5
NuGet\Install-Package MujahidHtmlEmailHelper -Version 1.0.5
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="MujahidHtmlEmailHelper" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MujahidHtmlEmailHelper --version 1.0.5
#r "nuget: MujahidHtmlEmailHelper, 1.0.5"
#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.
// 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 using Html String, but we're focussing on Html File methode here.

    1 Install : MujahidHtmlEmailHelper from NuGet

    Install 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 for Welcome.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 use SmtpClient.

    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

    result image

Product 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. 
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.0.5 505 9/6/2020
1.0.4 535 9/5/2020
1.0.2 395 9/3/2020
1.0.1 397 9/3/2020