如何通过电子邮件发送包含图像的gridview

时间:2015-08-18 15:47:38

标签: c# asp.net gridview

我必须通过电子邮件发送包含图片列的GridViewGridView中显示的图像来自数据库,因此图像存储在那里而不是本地文件夹中。

这是我的代码:

  public void SendHTMLMail()
   {
       MailMessage Msg = new MailMessage();
       lblcomfirmationmail.Text = Session["Useremail"].ToString();
       Msg.From = new MailAddress(lblcomfirmationmail.Text);
       Msg.To.Add(lblcomfirmationmail.Text);
       Msg.Subject = "Your Order Details";
       Msg.Body += "Please check below data <br/><br/>";
       Msg.Body += GetGridviewData(Gridorderconfirmation);
       Msg.IsBodyHtml = true;
       Msg.BodyEncoding = Encoding.UTF8;
       SmtpClient smtp = new SmtpClient();
       smtp.Host = "smtp.gmail.com";
       smtp.Port = 587;
       smtp.Credentials = new System.Net.NetworkCredential("venmanirsalimited@gmail.com", "");
       smtp.EnableSsl = true;
       smtp.Send(Msg);
   }


 public string GetGridviewData(GridView gv)
   {
       StringBuilder strBuilder = new StringBuilder();
       StringWriter strWriter = new StringWriter(strBuilder);
       HtmlTextWriter htw = new HtmlTextWriter(strWriter);
       gv.RenderControl(htw);
       return strBuilder.ToString();
   }



  public override void VerifyRenderingInServerForm(Control control)
   {

   }
protected void Payimgbtn_Click(object sender, ImageClickEventArgs e)
   {
       SendHTMLMail();
       Response.Redirect("~/Payment.aspx");
   }

我可以通过邮件发送所有详细信息,除了图片。我怎样才能使这个工作?

1 个答案:

答案 0 :(得分:0)

从文件中获取图像时,例如,您的方法是:&#34;〜/ Images /&#34; +。 而不是&#34;〜&#34;使用您当前的网址。 例如&#34; yourdomain.com/Images /&#34;。它对我有用。