代码如下,在本机可以,但上传到服务器之后就不行,偶尔能成功发送一次,查看过服务器环境和测试环境的IIS配置是一样的。
MailMessage myEmail = new MailMessage();
            if (string.IsNullOrEmpty(this.MailFromName))
            {
                myEmail.From = this.MailServerUserName;
            }
            else
            {
                myEmail.From = string.Format(@"""{0}"" <{1}>", this.MailFromName, this.MailServerUserName);
            }
            
myEmail.Subject = this.Subject;
myEmail.Body = this.Body;
myEmail.Priority = this.Priority; 
myEmail.BodyFormat = this.IsHtml?MailFormat.Html:MailFormat.Text; //邮件形式,.Text、.Html  // 通过SMTP服务器验证
            myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", this.MailDomain);
myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.MailServerUserName);
myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpaccountname",this.MailServerUserName);
myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.MailServerPassword);
myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",this.MailDomainPort); System.Web.Mail.SmtpMail.SmtpServer = this.MailDomain;