我现在有一个 aspx页面, 我想实现的功能就是
将这个页面 作为邮箱内容 发送给 指定客户
但似乎 不能直接发送 aspx页面,要将其转为 html页面。
问题1: 怎么将我这个aspx页面转为 html,并且能够保留原有的样式?发送到邮箱的时候保持?
团购网 , 大众点评网等他们发邮件 发的页面 都是怎么实现的?
问题2: 页面上的链接怎么处理?
在此先谢过 各位大侠
将这个页面 作为邮箱内容 发送给 指定客户
但似乎 不能直接发送 aspx页面,要将其转为 html页面。
问题1: 怎么将我这个aspx页面转为 html,并且能够保留原有的样式?发送到邮箱的时候保持?
团购网 , 大众点评网等他们发邮件 发的页面 都是怎么实现的?
问题2: 页面上的链接怎么处理?
在此先谢过 各位大侠
解决方案 »
- asp如何调用.net的webservice读写cookie
- VS2008 C# ajax div 调入网页
- 关于asp.net的前景希望大家讨论下
- [谢谢]split怎么样用呢??比如:
- 一个弱智的问题如何把SQL2000的datetime 字段中的时-分-秒去掉?
- 从哪下载ASP。net
- RegisterStartupScript的方法,无法显示脚本代码。
- 没见过的错误
- DataGrid问题!没分了,希望能帮我一下!
- 请问各位,DataSet,DataTable,DataView之间的关系,以及该如何结合DataGrid运用,达到要求
- .net用户控件缓存的一个参数的问题,.....
- 页面使用多个UpdatePanel控件
用浏览器单开此页面,保存就转成了html,包含样式等
问题2: 页面上的链接怎么处理?
相对路径应该改一改,都应该改为www的路径
问题2:相对路径转为绝对路径
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); 要发送的这样输出然后发送
里面的链接全部改成绝对地址。
还需要添加一个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>
{ 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);
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;
}
它好像只要是一个链接额。内容是嵌进去的。
所以我用代码写<iframe>标签
邮箱却是不解析的。。不懂了
最好直接用iframe外联到你网站的页面
[code=HTML]
<html>
<body>
<pre>
----------------------------------------------------------------------
个人网站--忘记密码
----------------------------------------------------------------------
{FullName}({LogonName}),请点击下面的链接重设密码:</pre>
<a href="{ActionUri}">{ActionUri}</a>
<pre>请于{Today}完成修改操作。如果上面链接无法点击,请将地址手工粘贴到浏览器地址栏再访问。
</pre>
</body>
</html>读取文件后,replace里面的"{FullName}",得到一个string,作为email的body,发送就好了。
/// <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;
}
你把页面所有有用的内容放在一个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
还要 我怎么批量再页面上的图片替换为 绝对路径的啊。。整个页面 狼藉一片。。
还有 页面里面的链接都是要改成 绝对路径的。----这个是要我在转化为html的改为绝对路径吗?
还有 我css放到页面之后 凡是里面 url(图片的地址的地方)--都被屏蔽为了url(#),这个可怎么办?