Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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. Now the problem is
The images are perfectly viewed in Yahoomail, but the image did not view with the Gmail.
How can I get this working?
My code as follows
private string getHTML(GridView gv)
   {

       this.Gridorderconfirmation.AllowPaging = false;
       this.Gridorderconfirmation.AllowSorting = false;
       this.Gridorderconfirmation.EditIndex = -1;

       this.GetselectedProductDetails();
       Gridorderconfirmation.Columns.RemoveAt(7);
       Gridorderconfirmation.DataBind();
       StringBuilder sb = new StringBuilder();
       StringWriter textwriter = new StringWriter(sb);
       HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);
       Gridorderconfirmation.RenderControl(htmlwriter);
       htmlwriter.Flush();
       textwriter.Flush();
       htmlwriter.Dispose();
       textwriter.Dispose();
       return sb.ToString();
   }

  protected void Payimgbtn_Click(object sender, ImageClickEventArgs e)
  {
        try
           {
string emailGR = getHTML(Gridorderconfirmation);
MailMessage Msg = new MailMessage();
lblcomfirmationmail.Text = Session["Useremail"].ToString();
lblmailtotalcost.Text = Session["cost"].ToString();
lblusername.Text = Session["username"].ToString();
Msg.From = new MailAddress(lblcomfirmationmail.Text);
Msg.To.Add(lblcomfirmationmail.Text);
Msg.Subject = "Your Order Details";
Msg.Body = "Dear "+lblusername.Text +"" + emailGR + "  " + "Total Amout:" + "  " + lblmailtotalcost.Text + "<br/>";
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("", "");
smtp.EnableSsl = true;
smtp.Send(Msg);
           }
           catch
           {
               string Msg = "<script>alert('Mail Sending Failed..try again!');</script>";
               ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", Msg, false);
               //Response.Write(@"<script language="'javascript'">alert('Mail Sending Failed..try again!')</script>");
           }
        this.Gridorderconfirmation.AllowPaging = true;
        this.Gridorderconfirmation.AllowSorting = true;
        this.Gridorderconfirmation.EditIndex = -1;
        this.GetselectedProductDetails();
}
}
Posted
Updated 18-Sep-15 19:01pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900