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 閱讀(76) 評論(0)  編輯  收藏

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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 香河县| 衡山县| 应城市| 通城县| 古浪县| 鄄城县| 东辽县| 龙门县| 连山| 中超| 浦城县| 甘洛县| 枣强县| 西乌珠穆沁旗| 乌拉特中旗| 垦利县| 龙州县| 壤塘县| 佛冈县| 新竹县| 雅江县| 吴旗县| 玉林市| 浦东新区| 宜昌市| 磐安县| 高碑店市| 焉耆| 增城市| 平阴县| 云林县| 柘城县| 赤城县| 勐海县| 巨野县| 桂林市| 镇宁| 阳信县| 天水市| 塔河县| 盈江县|