导航

c# 发送邮件

Posted on 2009-05-27 11:18  阳光有约  阅读(185)  评论(0编辑  收藏  举报

引用

System.Net.Mail

 

 

SmtpClient client = new SmtpClient("smtp.sina.com");   //设置邮件协议
                client.UseDefaultCredentials = false;//这一句得写前面
                client.DeliveryMethod = SmtpDeliveryMethod.Network; //通过网络发送到Smtp服务器
                client.Credentials = new NetworkCredential("sunny_oyh", "123456987"); //通过用户名和密码 认证

                MailMessage mmsg = new MailMessage(new MailAddress("sunny_oyh@sina.com"), new MailAddress("ouyanghua568@126.com")); //发件人和收件人的邮箱地址
                mmsg.Subject = "mail subject";      //邮件主题
                mmsg.SubjectEncoding = Encoding.UTF8;   //主题编码
                mmsg.Body = "mailbody";         //邮件正文
                mmsg.BodyEncoding = Encoding.UTF8;      //正文编码
                mmsg.IsBodyHtml = false;    //设置为HTML格式          
                mmsg.Priority = MailPriority.High;   //优先级

                client.Send(mmsg);