把.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;
}