Ref:
ASP.Net : Send email with Images embedded in Rich Text HTML body
Please refer this link
Handler.aspx
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
DataTable dt = new DataTable();
int id = Convert.ToInt32(context.Request.QueryString["Id"]);
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Select ContentType, Data From tblFiles Where Id = @Id"))
{
using (System.Data.SqlClient.SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Parameters.AddWithValue("@Id", id);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
context.Response.ContentType = dt.Rows[0]["ContentType"].ToString();
context.Response.BinaryWrite((byte[])dt.Rows[0]["Data"]);
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
HTML File
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
<img src = "{ImageUrl}" /><br /><br />
<div style = "border-top:3px solid #22BCE5"> </div>
<span style = "font-family:Arial;font-size:10pt">
Hello <b>{UserName}</b>,<br /><br />
A new article has been published on ASPSnippets.<br /><br />
<a style = "color:#22BCE5" href = "{Url}">{Title}</a><br />
{Description}
<br /><br />
Thanks<br />
ASPSnippets
</span>
</body>
</html>
Default.aspx.cs
private string PopulateBody(string userName, string title, string url, string description)
{
string body = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{ImageUrl}", Request.Url.Scheme + "://" + Request.Url.Authority + ResolveUrl("~/Handler.aspx?Id=1"));
body = body.Replace("{UserName}", userName);
body = body.Replace("{Title}", title);
body = body.Replace("{Url}", url);
body = body.Replace("{Description}", description);
return body;
}
Other code will remain same. Please refer the above reference link.