C#邮件发送
1 public static void CreateCopyMessage() { 2 MailAddress from = new MailAddress("yang@163.com"); 3 MailAddress to = new MailAddress("3@qq.com"); 4 MailMessage message = new MailMessage(from, to); 5 //邮件内容"; 6 message.Subject = "主题"; 7 message.Body = "内容"; 8 9 message.CC.Add("1@qq.com");//添加抄送 10 SmtpClient client = new SmtpClient("smtp.163.com"); 11 12 // Include credentials if the server requires them. 13 client.Credentials = new NetworkCredential("邮箱帐号", "密码");
15 Console.WriteLine("Sending an e-mail message to {0} at {1} by using the SMTP host={2}.", 16 to.User, to.Host, client.Host); 17 18 try { 19 client.Send(message); 20 } 21 catch (Exception ex) { 22 Console.WriteLine("Exception caught in CreateCopyMessage(): {0}", 23 ex.ToString()); 24 } 25 }