首页 > 解决方案 > 如何在同一电子邮件正文中添加控制图和网格视图?

问题描述

下面的代码在正文电子邮件中发送 gridview。如何添加图表以显示在正文电子邮件中(不是通过附件)。我尝试使用“AlternateViews.Add”,但 gridview 消失了。

protected void btn_sendmail_Click(object sender, EventArgs e)
{

            try
            {
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress("Ttest@xxx.com", "website (Do not reply)");
                mm.To.Add(ConfigurationManager.AppSettings["MailDailyReport"]);
                mm.Subject = DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy");
                mm.Body = "<span style='font-family:Calibri;font-size:12pt;'>Dear all, <br/>";
                mm.Body += "Please find the details of daily production report for " + DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy") + " in picture below.";
                mm.Body += "<br/>";
                mm.Body += " ";
                mm.Body += GetGridviewData(gvProdReport);

                mm.Body += "Group by";
                mm.Body += GetSubGridviewData(gvSubTotal);
                mm.Body += "<br/>";
                mm.Body += "If you have any questions or comments do feel free to reply all.";
                mm.Body += "</splan>";

                

                mm.IsBodyHtml = true;
                SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["MailServer"]);
                SmtpServer.Credentials = new System.Net.NetworkCredential("Ttest@xxx.com", "Call5191");

                SmtpServer.Send(mm);
                lbl_result.Text = "Send complete!";
            }
            catch (Exception ex)
            {
                lbl_result.Text = "Send incomplete! message :" + ex.ToString();
                lbl_result.ForeColor = Color.Red;
            }
}
            

标签: c#asp.net

解决方案


检查此链接:

通过电子邮件发送图表

第 1 步:创建图表

步骤2:创建图表后到图片base64string

第 3 步:在您的邮件中传递 base64 字符串

第 4 步:发送并检查您的邮箱

此外,如果您需要发送网格视图数据,那么您需要使用 HTML 设置一组数据,然后发送。

https://www.aspsnippets.com/Articles/How-to-send-GridView-data-in-email-in-ASPNet.aspx


推荐阅读