我现在有一个 aspx页面, 我想实现的功能就是
将这个页面 作为邮箱内容 发送给 指定客户
但似乎 不能直接发送 aspx页面,要将其转为 html页面。
问题1: 怎么将我这个aspx页面转为 html,并且能够保留原有的样式?发送到邮箱的时候保持?
        团购网 , 大众点评网等他们发邮件 发的页面 都是怎么实现的?
问题2: 页面上的链接怎么处理?
在此先谢过 各位大侠

解决方案 »

  1.   

    问题1: 怎么将我这个aspx页面转为 html,并且能够保留原有的样式?发送到邮箱的时候保持?
    用浏览器单开此页面,保存就转成了html,包含样式等
    问题2: 页面上的链接怎么处理?
    相对路径应该改一改,都应该改为www的路径
      

  2.   

    问题1:IO打开文件,用正则截取需要的内容(包括css、html)
    问题2:相对路径转为绝对路径
      

  3.   

    你这样的方式 其实不太好 很多邮箱不支持 不过既然你愿意这样做那么 如楼上所说,你页面数据全部自己在后台获取到 通过httprequest 然后以html格式 复制粘贴到你的EMIAL编辑器里面。HTML代码有了,但是图片链接怎么处理呢。这个就需要绝对路径了,比如http://www.qq.com/img/a.jpg这样一个路径。那么别人打开邮件的时候就可以直接看到这个图片。--------------------同时现在目前还有一个比较好的方式就是,通过图片,在图片上加热点的方式。具体你可以看下京东或苏宁,我看他们有时候就是图片+热点方式。
      

  4.   

    string html = string.Empty;  html += ("<html><head>");
      html += (string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
      html += (string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
      try
      {
      for (int i = 0; i < Inputs.Keys.Count; i++)
      {
      html += (string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
      }
      html += ("</form>");
      html += ("</body></html>");  System.Web.HttpContext.Current.Response.Write(html); 要发送的这样输出然后发送
      

  5.   

    直接生成HTML格式的网页,这样才可以直接发送到邮箱里,
    里面的链接全部改成绝对地址。
      

  6.   

    这个功能我前段时间做过,你需要先在项目中另外搭建1个.htm文件,把你需要发送的页面代码框架copy过去,把需要传递的参数字段用自定义字段来代替:<img src="##IndexUrl2####Barcode##" />像这样。
    还需要添加一个xml文件:
    <?xml version="1.0" encoding="utf-8" ?>
    <config>
      <share>
        <!--服务器地址-->
        <IndexUrl>参数地址</IndexUrl>
        <IndexUrl2>参数地址</IndexUrl2>
      </share>
      <email>
        <!--SMTP事务主机名称-->
        <MailHost></MailHost>
        <!--SMTP事务端口-->
        <MailPort></MailPort>
        <!--SMTP事务用户名-->
        <MailName></MailName>
        <!--SMTP事务密码-->
        <MailPwd></MailPwd>
        <!--********************************************************************-->
        <!--邮件发送人地址-->
        <MailAddress></MailAddress>
        <!--邮件密送对象-->
        <BCC></BCC>
        <!--邮件抄送对象-->
        <CC></CC>
        <!--邮件发送人中文-->
        <MailFromCN></MailFromCN>
        <!--邮件发送人英文-->
        <MailFromEN></MailFromEN>
        <!--邮件主题中文-->
        <SubjectCN></SubjectCN>
        <!--邮件主题英文-->
        <SubjectEN></SubjectEN>
      </email>
    </config>
      

  7.   

    然后再后台控制参数:    private void SendMail(Visitor visitor, string langs)
        {        string path = langs == "en" ? "http://" + serverPath + "/EmailTemplet/regen.htm" : "http://" + serverPath + "/EmailTemplet/regcn.htm";
            StringBuilder sb = getHtml(path);
            sb = sb.Replace("##IndexUrl##", XmlConfig.GetValue("IndexUrl")).Replace("##IndexUrl2##", XmlConfig.GetValue("IndexUrl2"));
            string body = sb.ToString();
            string to = visitor.Email;        body = body.Replace("##title##", visitor.Title).Replace("##First Name##", visitor.FirstName).Replace("##Family Name##", visitor.FamilyName).Replace("##Company Name##", visitor.CompanyCn).Replace("##Address##", visitor.Address1).Replace("##Province##", visitor.Province).Replace("##Code##", visitor.PostalCode).Replace("##Country##", langs == "en" ? GetCountryEn(visitor.Country) : GetCountryCn(visitor.Country)).Replace("##Email##", visitor.Email).Replace("##ConfirmNo##", visitor.ConfirmNo).Replace("##Barcode##", "Barcode/Barcode.aspx?id=" + visitor.ConfirmNo + "&code=" + code + "");
            Mail.Send(to, body, langs);
            Response.Write("<script>alert('" + (langs == "en" ? "Send sucess" : "发送成功") + "')</script>");
        }
        private string code = "128";
        private string serverPath = string.Format("{0}:{1}{2}", HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, HttpContext.Current.Request.ApplicationPath);
      

  8.   

    还有两种办法。
    1. 使用WebClient对象,载入制定页面,获得页面的data,然后发送:        WebClient wc = new WebClient();
            byte[] pagedata = wc.DownloadData(Request.Url.Scheme + Request.Url.Host + ":" + Request.Url.Port + "/" + Request.ApplicationPath + "/go1.aspx" );   // 要载入的页面
            string myDataBuffer = Encoding.Default.GetString(pagedata);
            Response.ContentType = "text/html";
            Response.Write(myDataBuffer);
    2. 跟五楼的办法一样,只是使用一个Html模板,读取模板文件,然后将数据填充进去,然后再输出:[HttpPost]
            public ActionResult ForgotPassword(string username, string checkcode)
            {
                string logonName = username.Trim();
                try
                {
                    //检测验证码是否正确
                    var iReturn = CheckCodeDecode(checkcode);
                    if (iReturn != 1)
                    {
                        ViewData.ModelState.AddModelError("LoginError", "验证码错误!请重新输入");
                        return View();
                    }                ExamineeBLL examineeBLL = new ExamineeBLL();
                    ExamineeEn examinee = examineeBLL.GetModelByName(logonName);
                    if (examinee == null)
                    {
                        ViewData.ModelState.AddModelError("LoginError", "用户名不存在!");
                        return View();
                    }                string body = GetRecoverPasswordContent(examinee);
                    string mailto = examinee.Email;
                    string subject = "TOEIC个人网站--忘记密码";
                    string returnMessage = string.Empty;
                    
                    EmailService ws = new EmailService();
                    if (!ws.SendEmail(mailto, subject, body, out returnMessage))
                        throw new Exception(returnMessage);
                    new Log("File_Log").Info(string.Format("忘记密码修改方式已发送至{0}。", mailto));
                    return View("ForgotPassword2", examinee);            }
                catch (Exception ex)
                {
                    new Log("File_Log").Error(string.Format(Log.LOG_TPL_EXCEPTION_S1, ex.Message, ex.StackTrace.ToString()));
                    return Alert(ex.Message, "JsTemp", "Login", "Home");
                }
            }        /// <summary>
            /// 创建考生忘记密码的邮件内容
            /// </summary>
            /// <param name="examinee"></param>
            /// <returns></returns>
            private string GetRecoverPasswordContent(ExamineeEn examinee)
            {
                string result = string.Empty;
                string today = DateTime.Today.ToString("yyyy-MM-dd");            string plain = string.Format("id={0}&date={1}", examinee.fExamineeId, today);
                string cypher = EncryptUrlParam(plain);            string actionPath = Url.Action("RecoverPassword", "Home", new { cypher = cypher });            // 去掉端口号 Updated by John 2011-04-13 13:35
                //string actionUri = Request.Url.AbsoluteUri.Replace(Request.RawUrl, actionPath);
                //int baseSite = actionUri.IndexOf(':');
                //int site = actionUri.IndexOf(':', baseSite + 1, actionUri.Length - baseSite - 1);
                //string repStr = actionUri.Substring(site, actionUri.IndexOf("/", site, actionUri.Length - site) - site);
                //actionUri = actionUri.Replace(repStr, "");            // 改为读取配置文件中的地址
                string actionUri = System.Configuration.ConfigurationManager.AppSettings["ForgotPasswordUrl"].ToString()
                    + actionPath;
                string filePath = Server.MapPath("~/Resources/ForgetPassword.htm");            using (StreamReader sr = new StreamReader(filePath))
                {
                    result = sr.ReadToEnd();
                    result = result.Replace("{FullName}", string.Format("{0} {1}", examinee.fFirstName, examinee.fLastName));
                    result = result.Replace("{LogonName}", examinee.fLogonName);
                    result = result.Replace("{Today}", today);
                    result = result.Replace("{ActionUri}", actionUri);
                }            return result;
            }
      

  9.   

    如果是我就用5楼的方法,最近我在通过json串优化页面
      

  10.   

    QQ的邮箱订阅功能 你们知道吗?
    它好像只要是一个链接额。内容是嵌进去的。
    所以我用代码写<iframe>标签
    邮箱却是不解析的。。不懂了
      

  11.   

    但是 我希望html格式,是我的原页面格式呀,这个 通过html模板能替换内容,能和我的一样吗?
      

  12.   

    不建议发html过去,因为邮箱自己的样式会覆盖到你的邮件里去
    最好直接用iframe外联到你网站的页面
      

  13.   

    可以的,Html模板,原本就是一个html文件,给你看看ForgetPassword.htm:
    [code=HTML]
    <html>
    <body>
    <pre>
    ----------------------------------------------------------------------
    个人网站--忘记密码
    ----------------------------------------------------------------------
    {FullName}({LogonName}),请点击下面的链接重设密码:</pre>
    <a href="{ActionUri}">{ActionUri}</a>
    <pre>请于{Today}完成修改操作。如果上面链接无法点击,请将地址手工粘贴到浏览器地址栏再访问。
    </pre>
    </body>
    </html>读取文件后,replace里面的"{FullName}",得到一个string,作为email的body,发送就好了。
      

  14.   

    我用iframe 但是 邮箱 不认识!!过滤掉了。。
      

  15.   

    那就抓取aspx页面转换成html 页面发送
    /// <summary>    
        /// 获取指定远程网页内容    
        /// </summary>    
        /// <param name="strUrl">所要查找的远程网页地址</param>    
        /// <param name="timeout">超时时长设置,一般设置为8000</param>    
        /// <param name="enterType">是否输出换行符,0不输出,1输出文本框换行</param>    
        /// <param name="EnCodeType">编码方式</param>    
        /// <returns></returns>    
        /// 也可考虑 static string    
       
        public string GetRequestString(string strUrl, int timeout, int enterType, Encoding EnCodeType)    
        {    
            string strResult;    
            try   
            {    
                HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl);    
                myReq.Timeout = timeout;    
                HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();    
                Stream myStream = HttpWResp.GetResponseStream();    
                StreamReader sr = new StreamReader(myStream, EnCodeType);    
                StringBuilder strBuilder = new StringBuilder();    
       
                while (-1 != sr.Peek())    
                {    
                    strBuilder.Append(sr.ReadLine());    
                    if (enterType == 1)    
                    {    
                        strBuilder.Append("\r\n");    
                    }    
                }    
                strResult = strBuilder.ToString();    
            }    
            catch (Exception err)    
            {    
                strResult = "请求错误:" + err.Message;    
            }    
       
            StreamWriter sw;    
            sw = File.CreateText(Server.MapPath("Index.htm"));    
            sw.WriteLine(strResult);    
            sw.Close();    
            Response.WriteFile(Server.MapPath("Test.htm"));    
            return strResult;    
       
        }   
      

  16.   

    这个问题我这几天刚碰到!!
    你把页面所有有用的内容放在一个div层里面,然后        System.IO.StringWriter swOut = new System.IO.StringWriter();
            HtmlTextWriter hTw = new HtmlTextWriter(swOut);
            DIVID.RenderControl(hTw);
            string ss = swOut.ToString();
    然后把ss作为邮箱的body发出去就行了。很有用的!!
    在前台的代码里div别忘加上runat=server
      

  17.   

    问题来了。我页面上的 title中 引入的 css 和 js这些 都没有了。。似乎被过滤了。。
    还要 我怎么批量再页面上的图片替换为 绝对路径的啊。。整个页面 狼藉一片。。
      

  18.   

    在接受到的邮件里面。。会自动过滤 引入的 css? 和 js?
      

  19.   

    关键是 我的css不能被引入呀
      

  20.   

    转换成word  再通过word 发送Email
      

  21.   

    css直接复制到页面里,js别指望了
      

  22.   

    直接页面另存为,就是HTML页面了,,在把页面当附件发
      

  23.   

    难道客户端 ,让人操作右键另存为html页面呀?
    还有 页面里面的链接都是要改成 绝对路径的。----这个是要我在转化为html的改为绝对路径吗?
    还有 我css放到页面之后 凡是里面 url(图片的地址的地方)--都被屏蔽为了url(#),这个可怎么办?