如何将ASP.NET表作为电子邮件发送而不是附件? [英] How can I send an ASP.NET table as an Email message not as an attachment?

查看:125
本文介绍了如何将ASP.NET表作为电子邮件发送而不是附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,我在default.aspx页面上有一个表格,但我想将表格作为消息发送到我的电子邮件但它正在发送,但它没有显示为表格



  //  这就是我在电子邮件中显示的方式..只是复制了一些......不是全部。 
< center id = ContentPlaceHolder1_cent > < table id = ContentPlaceHolder1_table4 border = 1 cellspacing = 0 width = 100 % style = font-size:small; color:#000000; collapse bordercolor = #999999 > < tr> < td colspan = 2 rowspan = 4 style = border:0 > < a href = http://www.difameg.com/default.aspx\"> < img id = ContentPlaceHolder1_Image1 src = ../ Images / Difameg.png /> < / a > < / td > < td colspan = 3 align = center style = border:0 > < h1>联系我们开启:< / h1 > < / td > < / tr > < tr> < td colspan = 3 align = right style = border:0; border-left-width:1 > 网站:< a target = _ blank href = http://www.123 .com> http: // www.123.com< / a> |电子邮件:< a href =mailto:info@123.com> info@123.com< / a>< / td> < / TR> < TR> < td colspan =3align =rightstyle =border:0>电话:+ 234-803-468-2529,+ 234-708-256-8755< / td> < / TR> < TR>







我正在看的格式应该在我的格式上正确完成电子邮件反而分散





  //  请参阅下面的我的电子邮件脚本..  

StringWriter sw = new StringWriter( );

System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
cent.RenderControl(htw);
string body = sw.ToString();

MailMessage msg = new MailMessage();

msg.From = new MailAddress(HttpUtility.HtmlEncode(TxtEmail.Text));
msg.To.Add( new MailAddress(TxtEmail.Text));


msg.Subject = From:me + - > + HttpUtility.HtmlEncode(TxtSubject.Text);
msg.Body = HttpUtility.HtmlEncode(body);
msg.IsBodyHtml = true ;
msg.Priority = MailPriority.Normal;
SmtpClient mSmtpClient = new SmtpClient();

mSmtpClient.Send(mMailMessage);
msg.Dispose();
MyClass.MyAlert( this 成功已发送 1234);





谢谢...亲切的帮助我..

解决方案

在调试时,检查字符串体的值。获取该值并创建一个HTML文件。

然后在某个浏览器中运行该文件并检查它是否正确显示。这也是它在邮件中出现的方式。



注意: - 应用于控件的CSS应该是内联的,否则,它不会像你期望的那样出现。



因此,检查HTML,你会明白的。


你必须使用下一个例子中的命令: br />

 StringWriter writer =  new  StringWriter(); 
HtmlTextWriter html = new HtmlTextWriter(writer);
//
html.RenderBeginTag(HtmlTextWriterTag.Pre);
html.WriteBreak();
html.WriteEncodedText( ...);
// ...
html.RenderEndTag();
html.Flush();
//
msg.Body = writer.ToString();


尝试



发送-AN-ASP-净表-AS-一个电子邮件消息 - 不作为附件 [ ^ ]



insert-html-code-in-email [ ^ ]

good day all, I have a table on my default.aspx page but i want to send the table as a message to my email but it is sending but it is not showing as table

// that is how it is showing on my email..just copied some..not all .
<center id="ContentPlaceHolder1_cent"> <table id="ContentPlaceHolder1_table4" border="1" cellspacing="0" width="100%" style=" font-size:small; color:#000000; collapse" bordercolor="#999999"> <tr> <td colspan="2" rowspan="4" style="border:0"> <a href="http://www.difameg.com/default.aspx"> <img id="ContentPlaceHolder1_Image1" src="../Images/Difameg.png" /></a> </td> <td colspan="3" align="center" style="border:0"> <h1>Contact Us On:</h1> </td> </tr> <tr> <td colspan="3" align="right" style="border:0; border-left-width:1"> Website: <a target="_blank" href="http://www.123.com">http://www.123.com</a> | Email: <a href="mailto:info@123.com">info@123.com</a></td> </tr> <tr> <td colspan="3" align="right" style="border:0"> Phone: +234-803-468-2529, +234-708-256-8755</td> </tr> <tr> 




what i am looking at is the the formatting should be done properly on my email instead scattering


// See my email script below..

 StringWriter sw = new StringWriter();
           
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
           cent.RenderControl(htw);
            string body = sw.ToString();

            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(HttpUtility.HtmlEncode(TxtEmail.Text));
           msg.To.Add(new MailAddress(TxtEmail.Text));

         
           msg.Subject = "From: me " + "--> " +  HttpUtility.HtmlEncode(TxtSubject.Text);
            msg.Body = HttpUtility.HtmlEncode(body);
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.Normal;
            SmtpClient mSmtpClient = new SmtpClient();
           
            mSmtpClient.Send(mMailMessage);
            msg.Dispose();
            MyClass.MyAlert(this, "Successfully Sent", "1234");



thanks... Kindl assist me on it..

解决方案

While debugging, check the value of string body. Take that value and create one HTML file.
Then run that file in some browser and check if it appearing correctly or not. That is how it is going to appear in mail too.

Note :- The CSS applied to controls should be inline, otherwise, it won't appear as you expect it to be.

So, check that HTML, you will get the idea.


You have to use commands like in the next example:

StringWriter writer = new StringWriter();
HtmlTextWriter html = new HtmlTextWriter(writer);
//
html.RenderBeginTag(HtmlTextWriterTag.Pre);
  html.WriteBreak();
  html.WriteEncodedText("...");
  //...
html.RenderEndTag();
html.Flush();
//
msg.Body = writer.ToString();


Try

send-an-asp-net-table-as-an-email-message-not-as-an-attachment[^]

insert-html-code-in-email[^]


这篇关于如何将ASP.NET表作为电子邮件发送而不是附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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