先是导入命名空间:using System.Net.Mail;
邮件发送代码:
MailAddress from = new MailAddress("sender gmail"); MailAddress to = new MailAddress("receiver mail"); MailMessage mail = new MailMessage(from,to); mail.Subject = "send email"; mail.Body = "u r a good boy!"; SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("sender mail", "sender psw"); client.Host = "smtp.gmail.com"; client.Port = 587; client.EnableSsl = true; try { client.Send(mail); MessageBox.Show("OK"); } catch(SmtpException ex) { MessageBox.Show(ex.ToString()); }