公司网站是用2.0写的,以前服务器在国内、在香港,用的都是win2003+IIS6,都能正常发送邮件,最近买了个美国服务器,自带配置是win2008和IIS7,3.0的.net,原来的代码发送邮件失败:        MailMessage mail = new MailMessage();
        string sysEmail, sysEmailPassword, sysEmailSMTP, sysEmailPort, email = "[email protected]";
        sysEmail = "[email protected]";
        sysEmailPassword = "xxxx";
        sysEmailSMTP = "smtp.xxx.cn";
        sysEmailPort = "25";
        mail.From = new MailAddress(sysEmail);
        mail.To.Add(email);
        mail.Subject = "测试邮件";
        mail.Body = "<h4>测试邮件</h4>电子邮件测试,时间:" + DateTime.Now.ToLongTimeString();
        mail.IsBodyHtml = true;
        System.Net.Mail.SmtpClient sc = new SmtpClient(sysEmailSMTP, int.Parse(sysEmailPort));
        sc.UseDefaultCredentials = true;
        sc.Credentials = new System.Net.NetworkCredential(sysEmail, sysEmailPassword);
        sc.DeliveryMethod = SmtpDeliveryMethod.Network;
        sc.Send(mail);
        Result = "<a>邮件已发送到" + email + ",请注意查收。</a>";提示“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.xxx:25”
发送失败,我检查了下,服务器没装杀毒软件,没防火墙,25端口也打开了,于是安装了SMTP服务,把原代码做了下修改        sc.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
        sc.PickupDirectoryLocation = @"C:\Inetpub\mailroot\Pickup";这下就不报错了,但是邮件在\mailroot\Queue\蹲了半天,就到\mailroot\Badmail\去了,查看.BDR
“Unable to deliver this message because the follow error was encountered: "This message is a delivery status notification that cannot be delivered.".
The specific error code was 0xC00402C7.
The message sender was <>.
The message was intended for the following recipients.
[email protected]
”改用Jmail算了        jmail.Message Jmail = new jmail.Message();
        String Subject = "测试邮件";
        String body = "<h4>测试邮件</h4>电子邮件测试,时间:";
        String FromEmail = "[email protected]";
        String ToEmail = "[email protected]";
        Jmail.AddRecipient(ToEmail, "", "");
        Jmail.From = FromEmail;
        Jmail.MailServerUserName = "[email protected]";
        Jmail.MailServerPassWord = "xxxxxx";
        Jmail.Subject = Subject;
        Jmail.Body = body + DateTime.Now.ToShortTimeString();
        Jmail.ContentType = "text/html;";
        Jmail.Send("smtp.xxx.cn", false);
        Jmail.Close();
Jmail组件已经注册过了,在本地测试可以发送,但是在服务器还是不行,提示“The message was undeliverable. All servers failed to receive the message ”求救啊!

解决方案 »

  1.   

    发邮件与IIS的版本是无关的!
      

  2.   

    这和你IIS7没有关系。。可以换个stmp服务器试试。。有这个错误的可能性太多了。可能是防火墙的问题。。也可能是你对Jmail。DLL操作权限不够原因太多了。。
      

  3.   

    服务商那边说没禁止发送邮件哎权限问题? 我给在服务器直接给文件夹加了EVERYONE所有权限啊
      

  4.   

    Jmail发送首先要通过邮件服务器验证。
    如果你的服务器不支持SMTP或者你的账号不能使用SMTP服务,那么就无法发送。
    注意....
    QQ邮箱默认情况下POP和SMTP服务是关闭的,进入您的QQ邮箱——》【设置】——》【账户】——》【POP3/IMAP/SMTP服务】,进行相关设置。
      

  5.   

    楼上这位大哥,那个代码里面的QQ邮箱是收信用的…… 发信用的邮箱我试过很多种了,从我们公司自己搭建的到163,qq,gmail之类都不行
      

  6.   

    哎,原来是服务商那边的问题Thank you for contacting Server Concierge regarding your server.I understand you are having issues sending email directly from one of your servers with us. Unfortunately, port 25 is blocked in an effort to prevent spam being sent from our network. You must use the proper email relaying server when sending email. If you are sending email using a script on your server you must use the mail server of "localhost". If you are sending email using an email client you must use "mail.yourdomain.com" as your incoming and outgoing mail server. Please also ensure that the proper smart host has been configured on your server within IIS 6.0 under the SMTP server. The smart host setting should read "p3smtpout.secureserver.net".