-
This package is usefull for sending HTML email by reading and replacing content from HTML file.
-
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.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.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>
- 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. } } }
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" }); } } }
- Create class in your project with any name, I'm using
mujahidxt/HtmlEmailHelper
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.