I have to send a GridView
containing an image column by email. The image displayed in the GridView
is from a database so the image is stored there and not in a local folder.
Here's my code:
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");
}
I'm able to send all the details in a mail except the Image. How can I get this working?