用div.innerhtml获得div中的html代码
解决方案 »
- ASP.NET登录, session传值
- 如何将ckeditor中图像属性中的图像与上传调换位置.怎么隐藏高级标签
- 操作treeview树源码
- 对于网站出现的各种错误,如何应对?
- extjs+asp.net OA开发疑惑
- 这个是什么原因?我在自己电脑上测试不会出现问题,在别的电脑上就提示这个!
- 关于TextBoxMode的问题
- 求三层架构的软件资料(有源代码的更好!最好是VB项目下建的ASP.NET WEB应用程序)
- Response的使用
- 未找到 Oracle 客户端和网络组件?
- 一条SQL语句strquery="select adx_name As Text from adx as TreeNode for xml auto,XMLDATA"
- 在存储过程里返回return 后,怎么在c#里得到这个值
把这段html作为字符串存储到数据库中
要发送邮件的时候,从数据库里面取出html字符串,用户据库里面的内容替换制定的特殊字符
然后作为email的body部分发送到客户的邮箱
要设置email的body部分为html,默认的一般是text
using CDO;
using System.IO;
public string GetHtml(string url)
{
WebRequest request=null;
WebResponse response=null;
Stream stream=null;
try
{
//获得html流
request=WebRequest.Create(url.Trim());
response=request.GetResponse();
stream=response.GetResponseStream();
int len=0,count=0;
long size=response.ContentLength;
byte[] bb=new byte [1024],container=new byte[(int)size];
string tt=""; //将html流读入到缓存区
while((len=stream.Read(bb,0,1024))>0)
{
for (int i=0;i<len;i++)
{
container[count]=bb[i];
count+=1;
}
} //将html数据读出来
tt+=System.Text.Encoding.Default.GetString(container,0,(int)size);
return (tt);
}
catch(System.Exception err1)
{
return err1.Message;
}
finally
{
if (stream!=null)
stream.Close();
request=null;
response=null;
}
} public string SendEmail_C(string to,string from,string bcc,string cc,string subject,
string attachments,string body,string bodyEncoding,
string smtpServer,string password,string sign)
{
string userName,err;
userName=from.Substring (0,from.IndexOf("@"));
if (password.Trim().Length==0) return ("密码不能为空!"); //验证密码是否为空
try
{
Configuration conf=new Configuration();
//以下部分设置参数(服务器,端号,用户名,密码,发送邮件帐号,回复邮箱帐号)
conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value=CdoSendUsing.cdoSendUsingPort;
conf.Fields[CdoConfiguration.cdoSMTPServer].Value=smtpServer.ToString();
conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value=25;
conf.Fields[CdoConfiguration.cdoSMTPAccountName].Value=userName;
conf.Fields[CdoConfiguration.cdoSendUserReplyEmailAddress].Value="\" " +
userName +"\" <" +from.ToString () +">";
conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value="\" " +
userName +"\" <" +from.ToString () +">";
conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value=CdoProtocolsAuthentication.cdoBasic;
conf.Fields[CdoConfiguration.cdoSendUserName].Value=userName;
conf.Fields[CdoConfiguration.cdoSendPassword].Value=password;
conf.Fields.Update();
MessageClass objMail=new MessageClass(); objMail.Configuration=conf;
if (to.Trim().Length!=0) //对发件人验证,如果为空,则返回错误
{
objMail.To=sign+"<" +to +">";
}
else
{
err="发件人不能为空!";
return (err);
}
if (from.Trim().Length!=0) //对收件人验证,如果为空,则返回错误
{
objMail.From=sign+ "<" +from+">" ;
}
else
{
err="收件人不能为空!";
return (err);
}
if (bcc.Trim().Length!=0) objMail.BCC =bcc; //写入抄送人
if (cc.Trim().Length!=0) objMail.CC =cc; //写入暗送人
if (subject.Trim().Length !=0)
{
objMail.Subject=subject ; //写入主题
}
else
{
err="主题不能为空!";
return (err);
}
//objMail.Charset="GB2312";
if (body.Trim().Length !=0)
{
if ((body.IndexOf("<html>",0)!=-1) ||(body.IndexOf("<HTML>",0)!=-1))
objMail.HTMLBody=body.ToString();
else
objMail.HTMLBody="<html><body>" + body.ToString() +"</body></html>" ;
objMail.BodyPart.Charset="gb2312";
objMail.HTMLBodyPart.Charset ="gb2312";
}
else
{
err="内容不能为空!";
return (err);
}
if (attachments!="") objMail.AddAttachment (attachments,userName,password); //写入附件
objMail.Send();
return ("发送成功!");
}
catch(System.Runtime.InteropServices.COMException Ee)
{
return (Ee.Message );
}
}
<script language="javascript">
document.Form1.mailbody.value=document.all("printdiv").outerHTML;
</script>//上面的代码是获取本页的HTML代码。
SmtpMail1.BodyFormat = Wakisoft.Mail.EmailBodyFormat.HTML
'SmtpMail1.Body = "赛宝WEB在线委托单测试:"
mailbody.Value = Replace(mailbody.Value, "", "")
mailbody.Value = Replace(mailbody.Value, "nbsp;", "")
SmtpMail1.Body += "<html><body>"
SmtpMail1.Body += mailbody.Value
SmtpMail1.Body += "<body></html>"
问题:我把mailbody.value给了MAIL的BODY后发现收不到邮件,但我手工
smtpmail.body+="<html><title><table><tr><td height=30 bgcolor=red>fafdsafdasfdsafdffdaf</td></tr></table></html>"
写却可以.我看了下获取后的HTML部分:
<input name="mailbody" id="mailbody" type="hidden" value="
<DIV id=printdiv><DIV align=center><FONT color=#330099 size=3>尊敬的客户:[东莞塘厦林村富士达电子厂 ]</FONT>,在您添加送检委托单时请您务必先阅读送检<A href="sjdsm.htm" target=_blank><FONT color=red>相关的说明</FONT></A><BR>
<TABLE id=Table1 style="WIDTH: 698px; HEIGHT: 54px" cellSpacing=0 cellPadding=0 width=698 border=0>
<TBODY>
<TR>
<TD style="WIDTH: 330px; HEIGHT: 8px" colSpan=3><FONT face=宋体></FONT></TD>