蓝宇网络 www.py668.com

非淡泊无以明志,非宁静无以致远。

导航

.net 2.0 的smtpclient百思不得期解

 代码:

        MailMessage message = new MailMessage(from, to,"","");
        //message.Subject = "nnnnnnn";
        //message.Body = "aaaaa";
        message.IsBodyHtml = false;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        SmtpClient client = new SmtpClient("mail.jonng.com");
        // Credentials are necessary if the server requires the client
        // to authenticate before it will send e-mail on the client's behalf.
        client.UseDefaultCredentials = false;
        client.Port = 25;
        client.Credentials = new NetworkCredential("lymph@jonng.com", "保密");

        //client.Credentials;
        client.Send(message);



web.config 设置
  <system.net>
    <mailSettings>
      <smtp from="lymph@jonng.com">
        <network host="mail.jonng.com" password=" " userName="lymph@jonng.com" defaultCredentials="false"/>
      </smtp>
    </mailSettings>
  </system.net>

用以上设死活都提示邮件标题有问题,怎样都发不出去,但用.NET 1.0的代码一发就可以了,真是怪事啊~

.NET 1.0的代码

        MailMessage mail = new MailMessage();
        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "lymph@jonng.com");
        mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", " ");
        mail.BodyFormat = MailFormat.Html;

        mail.From = "lymph@jonng.com";
        mail.To = txtEmail.Text;
        mail.Subject = "adfadf";
        mail.Body = "asdfsadfsd";

        SmtpMail.SmtpServer = "mail.jonng.com";
        SmtpMail.Send(mail);

posted on 2006-09-05 15:23  罗记  阅读(235)  评论(0)    收藏  举报