首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

用system.net.mail来发送邮件,出现错误!

2012-02-08 
用system.net.mail来发送邮件,出现异常!急%@PageLanguage C# %%@ImportNamespace System.Net.Mail

用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>
                &nbsp; <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   />
                <br   />
                <asp:Label   ID= "Label4 "   runat= "server "   Text= "附件: "> </asp:Label>


                &nbsp;
                <asp:FileUpload   ID= "FileUpload1 "   runat= "server "   /> <br   />
                <br   />
                <asp:Label   ID= "Label3 "   runat= "server "   Text= "内容: "> </asp:Label> <br   />
                <asp:TextBox   ID= "TextBox3 "   runat= "server "   Height= "176px "   Width= "348px "> </asp:TextBox> <br   />
                <br   />
                <br   />
                <asp:Button   ID= "Button1 "   runat= "server "   Text= "发送 "   OnClick= "Button1_Click "   />
                <asp:Button   ID= "Button2 "   runat= "server "   Text= "取消 "   /> </div>
        </form>
</body>
</html>


[解决办法]
在IIS里打开了简单邮件协议了吗?
[解决办法]
把你的防火墙关闭试试
[解决办法]
在web.config中还需要配制
[解决办法]
发送邮件的代码很多,如果排除代码的原因的话

你可以仔细看看防火墙或杀毒软件的设置

热点排行