C#实现邮件发送功能

        private void button1_Click(object sender, EventArgs e)
        {
            //创建一个邮件对像
            MailMessage mailObject = new MailMessage();
            //设置发件人
            mailObject.From = new MailAddress("lqwvje@163.com");
            //设置收件人
            mailObject.To.Add(new MailAddress("78630559@qq.com"));
            //设置邮件主题
            mailObject.SubjectEncoding = Encoding.UTF8;
            mailObject.Subject = "lqwvje测试邮件";

            mailObject.BodyEncoding = Encoding.UTF8;//编码
            mailObject.Body = "我是罗分明,这是一个测试邮件";

            //创建一个发送邮件的对像 服务地址和端口
            SmtpClient smtpClient = new SmtpClient("smtp.163.com", 25);
            //帐号密码一定要正确
            smtpClient.Credentials = new NetworkCredential("lqwvje", "123456");
            smtpClient.Send(mailObject);
            MessageBox.Show("ok");
        }

评论