using System;
          using System.Data;
          using System.Configuration;
          using System.Web;
          using System.Web.Security;
          using System.Web.UI;
          using System.Web.UI.WebControls;
          using System.Web.UI.WebControls.WebParts;
          using System.Web.UI.HtmlControls;
          using System.Web.Mail;
          namespace BaseProject.Classes.Util
          {
              public class MailManage
              {
                  public bool SendMail(string toMail, string subject, string body)
                  {
                      try
                      {
                          string fromMail = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["mailService"] ?? "");
                          MailMessage myMail = new MailMessage();
                          myMail.From = fromMail;
                          myMail.To = toMail;

                          myMail.Subject = subject;
                          myMail.Body = body;
                          myMail.BodyFormat = MailFormat.Html;

                          ////附件
                          //string ServerFileName = "";
                          //if (this.upfile.PostedFile.ContentLength != 0)
                          //{
                          //    string upFileName = this.upfile.PostedFile.FileName;
                          //    string[] strTemp = upFileName.Split('.');
                          //    string upFileExp = strTemp[strTemp.Length - 1].ToString();
                          //    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                          //    this.upfile.PostedFile.SaveAs(ServerFileName);
                          //    myMail.Attachments.Add(new MailAttachment(ServerFileName));
                          //}


                          myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                          myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["mailUser"] ?? "")); //發送方郵件帳戶
                          myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["mailPass"] ?? "")); //發送方郵件密碼

                          SmtpMail.SmtpServer = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                          SmtpMail.Send(myMail);

                          return true;
                      }
                      catch
                      {
                          return false;
                      }
                  }
              }
          }

          posted on 2009-04-02 18:35 sanmao 閱讀(80) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 梁河县| 瑞安市| 晴隆县| 武汉市| 凤凰县| 闽侯县| 丁青县| 绥芬河市| 五河县| 烟台市| 宁乡县| 凤翔县| 丽江市| 湖南省| 泰州市| 全椒县| 西乌| 家居| 洪雅县| 新野县| 枣强县| 江津市| 凤城市| 民乐县| 古丈县| 许昌市| 平安县| 石阡县| 北京市| 苍南县| 平江县| 合阳县| 化隆| 灌南县| 宝丰县| 湖北省| 肥城市| 元阳县| 万宁市| 孟津县| 临邑县|