日期:2014-05-18 浏览次数:20464 次
private void btntest_Click(object sender, EventArgs e) { MailMessage message = new MailMessage(); // if (FileUpload1.PostedFile.FileName != "") // { // Attachment att = new Attachment("d://test.txt");//发送附件的内容 // message.Attachments.Add(att); // } message.From = new MailAddress("xxx@126.com", "kevin", Encoding.UTF8); message.To.Add("xxx@126.com"); //收件人邮箱地址可以是多个以实现群发 message.Subject = "test2"; message.Body = "test2"; //message.Attachments.Add(objMailAttachment); message.IsBodyHtml = false; //是否为html格式 message.Priority = MailPriority.High; //发送邮件的优先等级 SmtpClient sc = new SmtpClient(); sc.Host = "smtp.126.com"; //指定发送邮件的服务器地址或IP sc.Port = 25; //指定发送邮件端口 sc.Credentials = new System.Net.NetworkCredential("knwolf@126.com", "kingwolf0923"); //指定登录服务器的用户名和密码 try { sc.Send(message); //发送邮件 } catch (Exception ex) { throw ex; } MessageBox.Show("发送成功!"); }