.net邮件发送非常好用

关键代码如下:

            SmtpClient client = new SmtpClient(smtp);
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(from, password);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            MailMessage message = new MailMessage(from, to, subject, body);
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = true;
            try
            {
                client.Send(message);
                return true;
            }
            catch
            {
                return false;
            }

注意:需要引用以下命名空间

      using System.Text;
      using System.Net;
      using System.Net.Mail;

上面代码中的参数说明如下:

smtp:邮件发送服务器
            from:邮件发送邮箱
            password:邮件发送邮箱密码
            to:发送到的邮箱
            subject:邮件主题
            body:邮件内容

posted @ 2010-10-28 09:31  大奇异果  阅读(250)  评论(0编辑  收藏  举报
Copyright ?2010 大奇异果 Contact QQ:408676935 E-mail:jialeifei@163.com