c# - 如何在同一电子邮件正文中添加控制图和网格视图?
问题描述
下面的代码在正文电子邮件中发送 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;
}
}
解决方案
检查此链接:
第 1 步:创建图表
步骤2:创建图表后到图片base64string
第 3 步:在您的邮件中传递 base64 字符串
第 4 步:发送并检查您的邮箱
此外,如果您需要发送网格视图数据,那么您需要使用 HTML 设置一组数据,然后发送。
https://www.aspsnippets.com/Articles/How-to-send-GridView-data-in-email-in-ASPNet.aspx
推荐阅读
- python-3.x - 用文本替换 html 文件中的表格......(例如@@##这里有一个表格)
- python - 来自 Docker nameko 服务器的空回复
- r - 将四个数值向量与公差区间进行比较并报告常用值
- python - python类中的多处理
- rest - 更改uri slug时PATCH与PUT的不同uri
- reactjs - 更改 MUI 芯片原色或副色
- java - 在 tomcat web 服务器启动后对自身执行请求
- python - 词干,我在我的程序中遇到错误
- javascript - 如何处理特定页面提交按钮的 Enter 按键功能 - Angular?
- sql - ')' 附近的语法不正确 CTE 中的错误