把.aspx页面当邮件体发送出去

冰岛男孩 2009-11-25 04:06:19
各位大虾们,小弟现在遇到一难题。
本人做了一个小型的考试网站,考生考完试点击提交答卷的时候要把他的答卷(.aspx里面有图片等)以邮件的形式发送给他,
现在的问题是发送过去的页面全乱了:图片不显示,页面的样式全错了,不知道有哪位大虾米做类似的项目,可以帮小弟解决一下此难题。
下面是我的发送邮件代码
public static bool SendMail(string StrTo, string StrBody, string strSubject, string strFrom, string strUserName, string strPwd, string strServer)
{
MailMessage mm = new MailMessage();
int smtp_port = 25;
bool smtp_ssl = false;
mm.From = strFrom;
mm.To = StrTo;
mm.Subject = strSubject;
mm.Body = HttpContentToString(StrBody);
mm.Priority = MailPriority.High;
mm.UrlContentBase = StrBody;
mm.BodyFormat = MailFormat.Html;
mm.BodyEncoding = Encoding.UTF8;
//设置为需要用户验证
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
//设置外部SMTP发送
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
//SMTP Server
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", strServer);
//设置端口号
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", smtp_port);
//SSL
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", smtp_ssl);
//设置验证用户名
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strUserName);
//设置验证密码
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPwd);
//SmtpMail.SmtpServer = strServer;

try
{
SmtpMail.Send(mm);
return true;
}
catch
{
return false;
}
}

public static string HttpContentToString(string url)//转换发送的网页
{
System.Net.WebRequest objRequest =System.Net.HttpWebRequest.Create(url);
StreamReader sr=new StreamReader(objRequest.GetResponse().GetResponseStream(),System.Text.Encoding.Default);
string result=sr.ReadToEnd();
sr.Close();
return result;
}
...全文
222 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
闲游四疯 2009-11-26
  • 打赏
  • 举报
回复
图片路径改成带域名的 样式放到style里面 不要放到css里面。。
hujia0815 2009-11-26
  • 打赏
  • 举报
回复
顶下
YnSky 2009-11-26
  • 打赏
  • 举报
回复
Up.关注..
冰岛男孩 2009-11-26
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 zcl24 的回复:]
使用 webBrose 组件把网页转成 mht再发送!
[/Quote]
如何使用webbrose把网页转换成mht,请说详细一点,本人是个新手,最好有源码。gahyyai@163.com
ckpbed 2009-11-25
  • 打赏
  • 举报
回复
把页面里的图片样式地址改为带域名的地址就可以。
zcl24 2009-11-25
  • 打赏
  • 举报
回复
webbrowser
zcl24 2009-11-25
  • 打赏
  • 举报
回复
使用 webBrose 组件把网页转成 mht再发送!
jshi123 2009-11-25
  • 打赏
  • 举报
回复
何必要转格式,调用SendMail方法时StrBody 参数写成全路径不是很方便?
http://www.xxx.co/xxx.aspx
lovexilove 2009-11-25
  • 打赏
  • 举报
回复
没做过这个 没试过会如何!帮顶
冰岛男孩 2009-11-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 wanghao3616 的回复:]
转成 mht 文件
使用 com组件  Microsoft CDO for Windows 2000 Library
[/Quote]
如何转换,请说详细一点,最好有源码,谢谢了.另外用全域名发送还是一样的,像百度之类的可以,我的页面不行.
com组件也没有用过
wanghao3616 2009-11-25
  • 打赏
  • 举报
回复
不过觉得还是 使用 全域名好点
wanghao3616 2009-11-25
  • 打赏
  • 举报
回复
转成 mht 文件
使用 com组件 Microsoft CDO for Windows 2000 Library
冰岛男孩 2009-11-25
  • 打赏
  • 举报
回复
那只能改成www.xxxx.com之类的了,没有其它解决办法吗
tzs2304 2009-11-25
  • 打赏
  • 举报
回复
../he和~/只能在你自己的环境下找到指定的css、图片
发送邮件到邮箱肯定找不到css和图片了
冰岛男孩 2009-11-25
  • 打赏
  • 举报
回复
就如楼上所说,就是后者.难道后者就不行,如何解决这个问题,请楼上的明说一下,难道要改www.xxx.com这样的才行?
tzs2304 2009-11-25
  • 打赏
  • 举报
回复
。。。
你发百度的首页或google的首页过去当然可以了,你自己的图片css路径也是www.xxx.com样式的还是../或~/之内的,如是后者就有问题了
冰岛男孩 2009-11-25
  • 打赏
  • 举报
回复
内容也发过去了,但内容都乱了,还有一些内容发不过去.但我发百度的首页或google的首页都可以发过去的啊,里面的内容一样的,发我自己的就不可以
Ann99 2009-11-25
  • 打赏
  • 举报
回复
你只发了aspx页面。没发相关的内容。比如CSS样式之类的吧
biaofanwo 2009-11-25
  • 打赏
  • 举报
回复
额 你是把这个页面的路径发过去?
你要是把你的页面当内容发过去肯定是会出错的啊
冰岛男孩 2009-11-25
  • 打赏
  • 举报
回复
不是,我发送www.baidu.com等一些知名网站就没问题
加载更多回复(2)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧