【问题标题】:How can I add the control chart and gridview in the same email body?如何在同一电子邮件正文中添加控制图和网格视图?
【发布时间】:2021-11-05 09:29:30
【问题描述】:

以下代码在正文电子邮件中发送 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】:

查看此链接:

Send Chart in Email

第 1 步:创建图表

第二步:创建chart后到图片base64string

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

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

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

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

【讨论】:

    猜你喜欢
    • 2011-07-11
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    相关资源
    最近更新 更多