我用。NET自带的System.Net.Mail发邮件,在本地发送都好用,可是传到服务器上时,点发送确提示错误:
从客户端(ErrorMsg="发送邮件失败。<br>")中检测到有潜在危险的 Request.QueryString 值。我的代码如下:MailMessage mail = new MailMessage();
            mail.From = new MailAddress("[email protected]");
            mail.To.Add(new MailAddress("[email protected]"));
            mail.Subject = txttaskName.Text;
            mail.Body = "发送直告明细:<br><br>用户帐号:" + userName + "<br><br>时 间:" + txttaskTime.Text + "<br><br>直告属性:" + HiddenField1.Value+ "<br><br>发送数量:" + sendCount.Text + "<br><br>短信内容:" + txtSms.Text + "<br><br>体验号码:" + alertMdnStr.Text;
            mail.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.Send(mail);

解决方案 »

  1.   

    你这玩意和邮件发送无关,只是页面回传时,表单里面有了不应该出现的HTML代码。类似代码存在潜在危险,所以服务器端报错了。在aspx页面第一行<%@ Page Language=“”>加入 ValidateRequest="false" 应该可以解决这个问题。但你的邮件发送也存在问题。因为现在有些邮件服务器是拒绝接收匿名发信的。通俗的讲就是,想要正常发送,除邮件发送服务器端允许smtp外,还需要输入必须的发送人的邮件用户名和密码。像你这种情况十有八九邮件都会发送不成功的。
      

  2.   

    这个问题在VS2005里面经常出现的,解决办法,加上页面有颜色标识的一段就OK了:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="Team_index" [b]enableEventValidation="false"[/b] %>
      

  3.   

    2楼说的对于“从客户端(ErrorMsg="发送邮件失败。 <br> ")中检测到有潜在危险的 Request.QueryString 值”问题的方法是正确的。。
      

  4.   

    代码是没贴全,服务器和端口我都在web.config里写的,我试试sxlfybb 说的
      

  5.   

    sxlfybb 和wguorun 
    ===================
    我在page里分别加了EnableEventValidation="false" ValidateRequest="false",可是还有这个错
      

  6.   

    1、你在服务器上要保证SNMP服务是开着。
    2、发送邮件需要配置发送人邮件用户名和密码。
    试一下吧。
      

  7.   

            public static bool SendMailSmtp(string MailFrom, string MailTo, string MailSubject, string MailBody)
            {//.net2发送邮件
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("mail.giftour.com");
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential("[email protected]", "12345678");       //帐号密码   
                client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.From = new System.Net.Mail.MailAddress(MailFrom, "", System.Text.Encoding.UTF8);
                message.To.Add(new System.Net.Mail.MailAddress(MailTo, "title", System.Text.Encoding.UTF8));
                message.IsBodyHtml = false;
                message.Subject = MailSubject;
                message.Body = MailBody;            try
                {
                    client.Send(message);
                    return true;
                }
                catch (System.Net.Mail.SmtpException ex) 
                {
                    return false;
                }        }
      

  8.   

    配置用户名与密码我在webconfig里写的
    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="smtp.163.com" password="*****" port="25" userName="andy.lf"/>
    </smtp>
    </mailSettings>
    </system.net>
    我把要发送的内容里的<br>去掉了,可是还是说这个错误