用div.innerhtml获得div中的html代码

解决方案 »

  1.   

    可以把html代码事先写好,把需要从数据库里面读取并填写的地方用特殊的字符串替代
    把这段html作为字符串存储到数据库中
    要发送邮件的时候,从数据库里面取出html字符串,用户据库里面的内容替换制定的特殊字符
    然后作为email的body部分发送到客户的邮箱
    要设置email的body部分为html,默认的一般是text
      

  2.   

    using System.Net;
    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 );
    }
    }
      

  3.   

    <INPUT id="mailbody" type="hidden" name="mailbody" runat="server">
    <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=&quot;sjdsm.htm&quot; target=_blank><FONT color=red>相关的说明</FONT></A><BR>
    <TABLE id=Table1 style=&quot;WIDTH: 698px; HEIGHT: 54px&quot; cellSpacing=0 cellPadding=0 width=698 border=0>
    <TBODY>
    <TR>
    <TD style=&quot;WIDTH: 330px; HEIGHT: 8px&quot; colSpan=3><FONT face=宋体></FONT></TD>