Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,
I am trying to send my listview data to email in asp.net.
if m sending text data then it is going properly to email and displaying text properly
but i want to send image which i m displaying in my listview with data to email..i tried one code but it is not displaying image in email..

please help thanks in advance..


This my email sending code:
C#
protected void btnsendemail_Click(object sender, EventArgs e)
    {
        SendHTMLMail();
    }

    public void SendHTMLMail()
    {
        SmtpClient smtpServer;
        MailMessage Msg = new MailMessage();
        smtpServer = new SmtpClient("smtp.gmail.com", 587);
        //this is the smtp of gmail because we are using if u use any other u can make use of that 

        smtpServer.EnableSsl = true;
        smtpServer.UseDefaultCredentials = true;
        smtpServer.Credentials = new System.Net.NetworkCredential("xxxxxxxxx@gmail.com", "xxxxxxxxxx");


        MailAddress fromMail = new MailAddress("raj.rautela14@gmail.com");
        // Sender e-mail address.
        Msg.From = fromMail;
        // Recipient e-mail address.
        Msg.To.Add(new MailAddress("rautela.raj@gmail.com"));
        // Subject of e-mail
        Msg.Subject = "Send ListView in EMail";
        Msg.Body += "Please check below data <br /><br />";
        Msg.Body += GetlistviewData(search);
        Msg.IsBodyHtml = true;
        smtpServer.Send(Msg);
    }
    // This Method is used to render gridview control
    public string GetlistviewData(ListView lv)
    {
        StringBuilder strBuilder = new StringBuilder();
        StringWriter strWriter = new StringWriter(strBuilder);
        HtmlTextWriter htw = new HtmlTextWriter(strWriter);
        lv.RenderControl(htw);
        return strBuilder.ToString();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }

[Edit]Code block added[/Edit]
Posted
Updated 7-Mar-13 20:49pm
v2
Comments
Raj.Rautela 8-Mar-13 1:47am    
what changes i should make to display image properly in email..

1 solution

You need to send the image embedded into the email

Embed image into email body[^]
 
Share this answer
 
Comments
Raj.Rautela 8-Mar-13 2:04am    
i am displaying data inside listview with image for eg "person's image and details" than what i should do to send image also to email..i'hv saved image in a folder and image-path in database and dynamically binding image-path in listview to display image.and i want to send the ssame image with details to email..what should i do..

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