//给制定邮箱发信息 private void 指定邮箱发信息ToolStripMenuItem_Click(object sender, EventArgs e) { string fuwuqi = textBox3.Text; //服务器 string fajiandizhi = textBox4.Text; //发件地址 string mima = textBox5.Text; //发件邮箱密码 string dizhi = comboBox1.Text; //收件地址 string biaoti = textBox1.Text; //邮件标题 string neirong = textBox2.Text; //邮件的内容 SendMail(fuwuqi,fajiandizhi,mima,dizhi, biaoti, neirong ); //调用发送邮件方法需要输入五个参数 } //发送邮件方法 public static void SendMail(string fuwuqi, string fajiandizhi, string mima, string dizhi, string biaoti, string neirong) { SmtpClient client = new SmtpClient(fuwuqi); //邮件类,造一个对象client client.Credentials = new System.Net.NetworkCredential(fajiandizhi, mima); //验证身份,通过发件人的地址和密码 client.DeliveryMethod = SmtpDeliveryMethod.Network; //指定如何发送电子邮件 System.Net.Mail.MailMessage message = new MailMessage(fajiandizhi, dizhi, biaoti, neirong); message.BodyEncoding = System.Text.Encoding.UTF8; //字符编码为Utf8 message.IsBodyHtml = true; //发送格式为html格式 try { client.Send(message); //讲指定的邮件发送到SMTP服务器以便传递 MessageBox.Show("发送成功"); } catch { MessageBox.Show("发送失败"); } }