1 public void SendEmail() 2 { 3 MailMessage msg = new MailMessage(); 4 5 msg.To.Add("to@qq.com");//收件人地址 6 //msg.CC.Add("cc@qq.com");//抄送人地址 7 8 msg.From = new MailAddress("from@qq.com", "Edward");//发件人邮箱,名称 9 10 msg.Subject = "This is a test email from QQ";//邮件标题 11 msg.SubjectEncoding = Encoding.UTF8;//标题格式为UTF8 12 13 msg.Body = "this is body";//邮件内容 14 msg.BodyEncoding = Encoding.UTF8;//内容格式为UTF8 15 16 SmtpClient client = new SmtpClient(); 17 18 client.Host = "smtp.qq.com";//SMTP服务器地址 19 client.Port = 587;//SMTP端口,QQ邮箱填写587 20 21 client.EnableSsl = true;//启用SSL加密 22 23 client.Credentials = new NetworkCredential("from@qq.com", "password");//发件人邮箱账号,密码(此处为授权码) 24 25 client.Send(msg);//发送邮件 26 27 }