这里用的是新浪邮箱,首先申请个邮箱,登录后,在“邮箱设置”里面设置下,否则发送的时候会报错!

 

打开邮箱设置--》账户,POP/SMTP设置,把“开启”勾上。
 

代码:

 
  
  1. using System.Net.Mail;  
  2.  
  3. protected void ButtonSend_Click(object sender, EventArgs e)  
  4. {  
  5. string from = "发件人邮箱  
  6. string subject = "测试";  
  7. string body = "test 测试,by C#,胡千好";  
  8. //收件人邮箱,多个邮箱用逗号分隔  
  9. string to = "";   
  10. MailMessage mailMessage = new MailMessage(fromto, subject.ToString(), body.ToString());  
  11. this.sendMail(mailMessage);  
  12. }  
  13.  
  14. private void sendMail(MailMessage mail)  
  15. {  
  16. SmtpClient smtpClient = new SmtpClient();  
  17. //smtpClient.EnableSsl = true;  
  18. smtpClient.Host = "smtp.sina.com";  
  19. //发件人邮箱和密码  
  20. smtpClient.Credentials = new NetworkCredential(mail.From.Address, "*******");  
  21. try  
  22. {  
  23. smtpClient.Send(mail);  
  24. Response.Write("发送成功");  
  25. }  
  26. catch(Exception e)  
  27. {  
  28. Response.Write("出错啦" + e.StackTrace.ToString());  
  29. }