用system.net.mail来发送邮件,出现异常!急
<%@ Page Language= "C# " %>
<%@ Import Namespace= "System.Net.Mail " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "server ">
protected void Button1_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress( "yuzhen20@126.com ");
msg.To.Add(new MailAddress(TextBox1.Text));
msg.Subject = TextBox1.Text;
string attachFile;
attachFile = @ "C:\Documents and Settings\X\桌面\1\说明.txt ";
System.Net.Mail.Attachment mailadd = new Attachment(attachFile);
msg.Attachments.Add(mailadd);
SmtpClient smt = new SmtpClient();
smt.Host = "smtp.126.com ";
smt.Send(msg);
}
</script>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:Label ID= "Label1 " runat= "server " Text= "收件人地址: "> </asp:Label>
<asp:TextBox ID= "TextBox1 " runat= "server " Width= "216px "> </asp:TextBox> <br />
<br />
<asp:Label ID= "Label2 " runat= "server " Text= "主题: "> </asp:Label>
<asp:TextBox ID= "TextBox2 " runat= "server " Width= "219px "> </asp:TextBox> <br />
&nbs