日期:2014-05-18  浏览次数:20426 次

有关发送邮件的错误
程序出现错误,望高手解答


程序如下:
<%@   Page   Language= "C# "   %>
<%@   Import   Namespace= "System "   %>
<%@   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(TextBox4.Text);
                msg.To.Add(new   MailAddress(TextBox1.Text));
                int   index1   =   TextBox4.Text.LastIndexOf( "@ ");
                string   str   =   TextBox4.Text.Substring(index1);
                string   str1   =   TextBox4.Text.Substring(0,   index1   +   1);
               
                msg.Subject   =   TextBox2.Text;
                msg.Body   =   TextBox3.Text;
                string   attachFile;
                attachFile=FileUpload1.FileName;
  
                System.Net.Mail.Attachment   mailadd   =   new   Attachment(FileUpload1.PostedFile.InputStream,   attachFile);


                msg.Attachments.Add(mailadd);

                SmtpClient   smt   =   new   SmtpClient();
                smt.DeliveryMethod   =   System.Net.Mail.SmtpDeliveryMethod.Network;
                string   smtpserver   =   "smtp. "   +   str;
                smt.Host   =   smtpserver;

                smt.Credentials   =   new   System.Net.NetworkCredential(str1,   TextBox5.Text.ToString());
                smt.Send(msg);
                Response.Write( "发送成功 ");
               

               
               
        }
</script>

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   id= "Head1 "   runat= "server ">
        <t