Title: email Send emara                                 If you need copy same format use firefox or chrome or safari but iexplorer not work


Preview of Code
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dapper;
using sendwithHtmlEmarah.Models;
 
 
namespace sendwithHtmlEmarah
{
    public partial class mysend : System.Web.UI.Page
    {
        public TabukDBEntities db = new TabukDBEntities();
 
        protected void Page_Load(object sender, EventArgs e)
        {
 
            send(0, "developers@mail.com");
            send(6, "developers@mail.com");
            send(16, "developers@mail.com");
            send(17, "developers@mail.com");
            send(1, "developers@mail.com");
 
            if (!IsPostBack)
            {
                var dept = (from c in db.lkpDepartments
                            orderby c.ID
                            select new { c.ID, c.Name }).ToList();
 
                DropDownList1.DataValueField = "id";
                DropDownList1.DataTextField = "name";
                DropDownList1.DataSource = dept;
                DropDownList1.DataBind();
            }
 
        }
        public bool SendEmailWithHtml(string emlClients, string eSubject, string htmlBody)
        {
 
            SmtpClient MySMTPServr = new SmtpClient("webmail.com");
            MailMessage msgEmail = new MailMessage();
            MailAddress emServer = new MailAddress("notification@mail.com", "تقرير عن المعاملات اليومية", System.Text.Encoding.UTF8);
            MailAddress emlClient = new MailAddress(emlClients);
 
            try
            {
                {
                    var withBlock = msgEmail;
                    // this code create alternateview to send html passed to the funciton 
                    System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlBody, null, "text/html");
                    htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
                    msgEmail.AlternateViews.Add(htmlView);
                    withBlock.From = emServer;
                    withBlock.To.Add(emlClients);
                    withBlock.Subject = eSubject;
                    // .Body = htmlBody
                    //    withBlock.Priority = MailPriority.High;
                }
 
                MySMTPServr.Send(msgEmail);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
 
        }
        //protected void Button1_Click(object sender, EventArgs e)
        protected void send(int deptNo, string email)
        {
            //SqlConnection conn = new SqlConnection(connectionString);
 
            var HijriDate = new HijriCalendar();
 
            var format = CultureInfo.GetCultureInfo("ar-SA");
 
            var hijri = DateTime.Now.AddDays(-3).ToString("yyyy/MM/dd", format);
            var date = DateTime.Now.AddDays(-3).ToString("dd-MM-yyyy");
 
            string dept = "";
 
 
 
            string Waredno = "";
            string Saderno = "";
            string ArchiveSaderNo0 = "";
            string ArchiveWaredNo0 = "";
            string NotarchiveWaredNo0 = "";
            string NotarchiveSaderNo0 = "";
 
            // dept
            var resutl = db.Database.SqlQuery<ArchiveWarid>("sp_archiveWaredNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                dept = resutl.Dept_Name;
            else
            {
                resutl = db.Database.SqlQuery<ArchiveWarid>("sp_NotarchiveWaredNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
                if (resutl != null)
                    dept = resutl.Dept_Name;
            }
 
            //warid
            resutl = db.Database.SqlQuery<ArchiveWarid>("sp_archiveWaredNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                ArchiveWaredNo0 = resutl.counts.ToString();
            //sadir
            resutl = db.Database.SqlQuery<ArchiveWarid>("sp_archiveSaderNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                ArchiveSaderNo0 = resutl.counts.ToString();
            //notarchivewarid
            resutl = db.Database.SqlQuery<ArchiveWarid>("sp_NotarchiveWaredNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                NotarchiveWaredNo0 = resutl.counts.ToString();
            //notarchivesadir
            resutl = db.Database.SqlQuery<ArchiveWarid>("sp_NotarchiveSaderNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                NotarchiveSaderNo0 = resutl.counts.ToString();
            //waridNo
            resutl = db.Database.SqlQuery<ArchiveWarid>("sp_sqlwaredNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                Waredno = resutl.counts.ToString();
            //sadirNo
            resutl = db.Database.SqlQuery<ArchiveWarid>("sp_sqlsaderNo @DeptNo, @Sdate",
                new SqlParameter { ParameterName = "DeptNo", SqlValue = deptNo }, new SqlParameter { ParameterName = "Sdate", SqlValue = hijri }).SingleOrDefault();
 
            if (resutl != null)
                Saderno = resutl.counts.ToString();
 
            if (!string.IsNullOrWhiteSpace(dept))
            {
 
                string message = "<div style=\"text-align:center;width:100%;margin:0px auto\">" +
                      "<fieldset>" +
                     "<img src=\"http://10.10.21.18/TestEGate/images/headerEmail.jpg\" style =\"width:99%\" />" +
                    "<h1 style=\"text-align: center;\"><span style=\"color: #ff0000;\">تقرير عن المعاملات اليومية لنظام الإتصالات الإدارية</span></h1>" +
                    "<p style=\"direction: rtl; text-align: center;\">التاريخ: " + hijri + "&nbsp; &nbsp; &nbsp; &nbsp;الموافق:&nbsp;" + date + "</p>" +
                    "<h2 style=\"direction: rtl;\">&nbsp;</h2>" +
                   "<h2 style=\"direction: rtl; \">الإدارة: " + dept + "</h2>" +
                    "<h4 style=\"direction: rtl; \">المعاملات الصادرة : " + Saderno + "</h4>" +
                    "<table style=\"height: 49px;\" width=\"499\">" +
                    "<tbody>" +
                    "<tr>" +
                    "<td style=\"width: 159px; text-align: center; \">" +
                    "<h4>المعاملات</h4>" +
                    "</td>" +
                    "<td style=\"direction: rtl; width: 159px; text-align: center; \">" +
                     "<h4>عدد المعاملات</h4>" +
                    "</td>" +
                    "</tr>" +
                    "<tr>" +
                     "<td style=\"width: 159px; text-align: right; \">المعاملات الغير مؤرشفة</td>" +
                     "<td style=\"width: 159px; \">" + NotarchiveSaderNo0 + "</td>" +
                    "<td style=\"width: 159px; text-align: center; \"></td>" +
                     "</tr>" +
                    "<tr>" +
                     "<td style=\"width: 159px; text-align: right; \">المعاملات المؤرشفة</td>" +
                     "<td style=\"width: 159px; \">" + ArchiveSaderNo0 + "</td>" +
                    "<td style=\"width: 159px; \"></td>" +
                     "</tr>" +
                    "</tbody>" +
                    "</table>" +
                     "<hr />" +
                    "<h4 style=\"direction: rtl; \">المعاملات الواردة: " + Waredno + "</h4>" +
                     "<table style=\"height: 49px;\" width=\"499\">" +
                    "<tbody>" +
                    "<tr>" +
                    "<td style=\"width: 159px; text-align: center; \">" +
                    "<h4>المعاملات</h4>" +
                    "</td>" +
                    "<td style=\"direction: rtl; width: 159px; text-align: center; \">" +
                     "<h4>عدد المعاملات</h4>" +
                    "</td>" +
                    "</tr>" +
                    "<tr>" +
                     "<td style=\"width: 159px; text-align: right; \">المعاملات الغير مؤرشفة</td>" +
                     "<td style=\"width: 159px; \">" + NotarchiveWaredNo0 + "</td>" +
                    "<td style=\"width: 159px; text-align: center; \">&nbsp;</td>" +
                     "</tr>" +
                    "<tr>" +
                     "<td style=\"width: 159px; text-align: right; \">المعاملات المؤرشفة</td>" +
                     "<td style=\"width: 159px; \">" + ArchiveWaredNo0 + "</td>" +
                    "<td style=\"width: 159px; \"></td>" +
                     "</tr>" +
                    "</tbody>" +
                    "</table>" +
                    "<p>&nbsp;</p>" +
                    "<p style=\"text-align: right;\">إمارة تبوك - الإدارة العامة لتقنية المعلومات</p>" +
                    "</fieldset>" +
                    "<div style=\"opacity:.2;height:20px;background-color:#006d30 !important;;text-align:center;width:99%;margin:0px auto\">" +
                "</div>";
 
 
                if (SendEmailWithHtml(email, dept, message))
                    lblmsg.Text = "successfully";
                else
                    lblmsg.Text = "Failure";
            }
        }
 
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblmsg.Text = DropDownList1.SelectedItem.Value;
        }
    }
}