日期:2014-05-17 浏览次数:20500 次
MailMessage msg; try { smtpclient = new SmtpClient("smtp服务器地址"); smtpclient.UseDefaultCredentials = true; smtpclient.Credentials = new NetworkCredential("登陆smtp服务器的用户名", "登陆smtp服务器的密码"); smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; msg = new MailMessage("发送邮件地址","接受邮件地址","邮件标题", "邮件内容"); //附件判断 if (tboxAttachment.Text.Length != 0) { attachment = new Attachment(tboxAttachment.Text); msg.Attachments.Add(attachment); } msg.BodyEncoding = Encoding.UTF8;//邮件编码格式 msg.IsBodyHtml = false;//邮件内容是否HTML smtpclient.Send(msg);//发送邮件 } catch (Exception err) { //这里写异常处理代码,比如记录异常到数据库什么的 }