System.Net.Mail.MailMessage发邮件在本地测试成功,上传到服务器也可以,但应用程序一发布之后再上传,就发送失败,找不到原因,也不好断点测试

解决方案 »

  1.   

    不是防火的问题,IIS里SMTP似乎一直没装过,我本机也没装过,
      

  2.   

    代码如下:
    public bool Send()
            {            System.Net.Mail.MailMessage myEmail = new System.Net.Mail.MailMessage();
                Encoding eEncod = Encoding.GetEncoding("utf-8");
                myEmail.From = new System.Net.Mail.MailAddress(this.From, this.From, eEncod);
                myEmail.To.Add(this._recipient);
                myEmail.Subject = this.Subject;
                myEmail.Body = this.Body;
                myEmail.Priority = System.Net.Mail.MailPriority.Normal;
                myEmail.IsBodyHtml = this.Html; //邮件形式,.Text、.Html 
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Host = this.MailDomain;
                smtp.Port = this.MailDomainPort;
                smtp.Credentials = new System.Net.NetworkCredential(this.MailServerUserName, this.MailServerPassWord);
                
                //当不是25端口(gmail:587)
                if (this.MailDomainPort != 25)
                {
                    smtp.EnableSsl = true;
                }
                //System.Web.Mail.SmtpMail.SmtpServer = this.MailDomain;            try
                {
                    smtp.Send(myEmail);
                }
                catch (System.Net.Mail.SmtpException e)
                {
                    string result = e.Message;
                    return false;
                }            return true;
            }
        }