Gridview数据发送邮件 [英] Gridview Data to send the Mail

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

问题描述





我有Gridview数据发送邮件。显示错误:无法建立连接,因为目标计算机主动拒绝它。这是我的代码。请帮助我。

Hi,

I have Gridview data to sent the mail. Showing Error : No connection could be made because the target machine actively refused it.This is my code.Please help me.

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);

this.SalesGrid.RenderControl(htmlWrite);
MemoryStream memorystream = new MemoryStream();
byte[] _bytes = Encoding.UTF8.GetBytes(stringWrite.ToString());
memorystream.Write(_bytes, 0, _bytes.Length);
memorystream.Seek(0, SeekOrigin.Begin);

MailMessage msg = new MailMessage("From Mail", "To Mail");
msg.Subject = "email test";
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(memorystream, "Report.xls"));
AlternateView View = null;
LinkedResource resource = null;
SmtpClient client = null;
StringBuilder msgText = new StringBuilder();
msgText.Append("Hi there,");
msgText.Append("Welcome to the new world programming.");
msgText.Append("Thanks");
msgText.Append("With regards,");
msgText.Append("");
msgText.Append("<table><table><tbody><tr><td>b</td><td><img src=\"cid:Image1\" /></td></tr></tbody></table>");
View = AlternateView.CreateAlternateViewFromString(msgText.ToString(),null, "text/html");
//AlternateView.CreateAlternateViewFromString(
resource = new LinkedResource((Server.MapPath("green_bg_Tab.gif")));
resource.ContentId = "Image1";
View.LinkedResources.Add(resource);
msg.AlternateViews.Add(View);
client = new SmtpClient();
client.Host = "mail.gmail.com";
//client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("From User Name", "Password");
client.Send(msg);

推荐答案

访问这些链接....

http://www.aspdotnet-suresh.com/2012/09/how -to-send-gridview-in-email-body-in.html [ ^ ]



http://www.aspsnippets.com/Articles/How-to-send -GridView-data-in-email-in-ASPNet.aspx [ ^ ]
visit these Links....
http://www.aspdotnet-suresh.com/2012/09/how-to-send-gridview-in-email-body-in.html[^]
or
http://www.aspsnippets.com/Articles/How-to-send-GridView-data-in-email-in-ASPNet.aspx[^]


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

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