将Listview数据发送到asp.net中的电子邮件 [英] Sending Listview Data to email in asp.net

查看:56
本文介绍了将Listview数据发送到asp.net中的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

我正在尝试将我的listview数据发送到asp.net中的电子邮件。

如果发送文本数据,那么它将正常发送到电子邮件和显示文字正确

但我想将我在listview中显示的图像发送到电子邮件..我尝试了一个代码,但它没有在电子邮件中显示图像..



请提前帮助谢谢..





这是我的邮箱发送代码:

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:

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 */
    }



已添加代码块[/编辑]


Code block added[/Edit]

推荐答案

您需要发送嵌入到电子邮件中的图像



将图像嵌入电子邮件正文 [ ^ ]
You need to send the image embedded into the email

Embed image into email body[^]


这篇关于将Listview数据发送到asp.net中的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆