当前位置:编程学习 > C#/ASP.NET >>

asp.net在服务器上不能调用System.Web.Mail.SmtpMail发送邮件

代码如下,在本机可以,但上传到服务器之后就不行,偶尔能成功发送一次,查看过服务器环境和测试环境的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; --------------------编程问答-------------------- 这个不可能是。
查查你的服务器安全和策略设置。
是不是把邮件的端口关了, 查查防火墙。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,