首先,要添加System.Net类的引用,然后根据下面的代码进行邮件发送。在发送附件的过程中,发现邮件发送后,被发送的附件一直被iis进程占用着,导致无法编辑或删除,最后查下来是要把MailMessage对象释放,所以后面添加了资源释放的代码。 protected void Mailsend() ...{ MailMessage mailMessage = new MailMessage(); string strBody; //发送人 mailMessage.From = new MailAddress("zzz@mail.com"); //接收人 mailMessage.To.Add("xxx@mail.com"); //邮件标题 mailMessage.Subject = "testmail"; //邮件内容 strBody = "<h2>testmail</h2><br>"; mailMessage.Body = strBody; //邮件内容使用html格式 mailMessage.IsBodyHtml = true; //抄送 mailMessage.CC.Add("yyy@mail.com"); //附件 mailMessage.Attachments.Add(new Attachment("d:/mail.rar")); SmtpClient smtpClient = new SmtpClient(); //smtp是否使用ssl安全认证 smtpClient.EnableSsl = false; //smtp服务器地址 smtpClient.Host = "smtp.mail.com"; //smtp服务端口 smtpClient.Port = 25; //smtp使用帐号 smtpClient.Credentials = new NetworkCredential("usid", "pwd"); try ...{ smtpClient.Send(mailMessage); Label1.Text = "ok"; } catch ...{ Label1.Text = "false"; } //释放资源 mail.Dispose(); mail = null; smtpClient = null; }