try { //准备邮件内容 MailMessage message = new MailMessage ("abc@163.com", "abc@163.com", "测试邮件发送", "查看附件 "); message.Attachments.Add(new Attachment(@"D:/a.txt")); message.Priority = MailPriority.High; message.IsBodyHtml = false; //准备安全凭证 NetworkCredential nc= new NetworkCredential("abc","邮箱密码"); //准备SMTP,发送电子邮件 SmtpClient client = new SmtpClient("smtp.163.com",25); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Credentials = nc; client.Send(message); MessageBox.Show("邮件发送成功!!"); } catch (FormatException ex) { MessageBox.Show(ex.Message); } catch (SmtpException ex) { MessageBox.Show(ex.Message); }