如果表tba中
name     editer      editer_mail
张三     2057001     [email protected]
张四     2057001     [email protected]
李四     2057001     [email protected]
王五     2057001     [email protected]测试     2087010     [email protected]
肥不     2087010     [email protected]
有有     2087010     [email protected]
七要     2087010     [email protected]点击一个按钮后,读取表tba
然后分别按editer的不同,给 editer发邮件,邮件的附件带上一excel
excel的内容就是editer对象的那些name比方给[email protected]发邮件
附件的excel中是
名字     
张三     
张四     
李四     
王五     

解决方案 »

  1.   

    点击按钮的时候,你先读取tba 表的name 获取数据集 生成临时的EXCEL文件
    然后再将EXCEL以附件的形式 发送给指定的人 不就可以了。
    具体发邮件的代码 你可以引用JMAIL 或者MS自带的。
      

  2.   

    MailAttachment myAttachment = new MailAttachment("");
    email.Attachments.Add(myAttachment);
    根据name生成EXCEL文件
      

  3.   

      public static int SendEmail(string mto, string msubject, string mbody, string MyMail, string mailPass)
        {        string from = MyMail;
            string pwd = mailPass;        string to = mto.Trim();
            MailMessage mail = new MailMessage(from, to);
            mail.Subject = msubject;
            mail.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            mail.Body = mbody;
            mail.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            mail.IsBodyHtml = true;
            string server = "";
            int port = 25;
            if (from.IndexOf("@gpres") != -1 || from.IndexOf("@gmail") != -1)
            {
                port = 587;
                server = "smtp.gmail.com";
            }
            else
            {
                port = 25;
                string temp;
                temp = from.Substring(from.LastIndexOf('@') + 1);
                server = "smtp." + temp;
            }
            SmtpClient sc = new SmtpClient(server, port);
            if (port != 25)
            {
                sc.EnableSsl = true;
            }
            sc.Credentials = new NetworkCredential(from, pwd);              try
            {
                sc.Send(mail);
                mail.Dispose();
                return 1;   //发送成功
            }
            catch (Exception ex)
            {
                //System.Web.HttpContext.Current.Response.Write(e.Message); 
                mail.Dispose();
                return 0;  //发送失败
            }
        }一般用这个方法发邮件
    能具体说下怎么形成excel并作为附件加上?
      

  4.   

     
    加上可以 带上附件
    mail.Attachments.Add(new Attachment(atta));但是atta得是具体某个目录底下的一个具体excel怎么直接 生成 excel,再将EXCEL以附件的形式 发送给指定的人,而不用先存在某个目录下
      

  5.   


    用Com,具体的操作word,excel的代码,搜一下都找得到的
      

  6.   


            
            
       
    Excel.Application excel1=new Excel.Application();
    int rowIndex=1;
    int colIndex=0;
          
    excel1.Application.Workbooks.Add(true);
           System.Data.DataTable tb=new DataTable();
            tb=AccessData.GreatDs(str).Tables[0];
    foreach(DataColumn col in tb.Column){
      colIndex++;
        
      excel1.Cells[1,colIndex]=col.ColumnName;
      }
    foreach(DataRow row in tb.Rows){
      rowIndex++;
      colIndex=0;
      foreach(DataColumn col in tb.Column){
          colIndex++;
          excel1.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
          }
       }
            

    //不可见的后台处理
      
    excel1.Visible=false;
    excel1.DisplayAlerts=false;
    //保存刚才创建的excel表格
    excel1.Save(MapPath("upfile/ExcelTable.xls"));
        
    excel1.Application.Quit();
    excel1.Quit();
    //释放使用的excel对象
    System.Runtime.InteropServices.Marshal.ReleaseComObject(excel1);
    GC.Collect();
    在网上找了下创建excel并保存的代码,
    但是从   //不可见的后台处理
    开始就出错了,excel1都点不出来的
      

  7.   

    Excel.Application excel1=new Excel.Application();
    int rowIndex=1;
    int colIndex=0;
        
    excel1.Application.Workbooks.Add(true);
      System.Data.DataTable tb=new DataTable();
      tb=AccessData.GreatDs(str).Tables[0];
    foreach(DataColumn col in tb.Column){
      colIndex++;
        
      excel1.Cells[1,colIndex]=col.ColumnName;
      }
    foreach(DataRow row in tb.Rows){
      rowIndex++;
      colIndex=0;
      foreach(DataColumn col in tb.Column){
      colIndex++;
      excel1.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
      }
      }
        
      
    //不可见的后台处理
       
    excel1.Visible=false;
    excel1.DisplayAlerts=false;
    //保存刚才创建的excel表格
    excel1.Save(MapPath("upfile/ExcelTable.xls"));
        
    excel1.Application.Quit();
    excel1.Quit();
    //释放使用的excel对象
    System.Runtime.InteropServices.Marshal.ReleaseComObject(excel1);
    GC.Collect();
      

  8.   

    不会直接 保存upfile/ExcelTable.xls
    而且出来提示要保存到那的对话框,
    得保存后才会再保存到excel1.Save(MapPath("upfile/ExcelTable.xls"));
      

  9.   

    最近也在研究 我的是一个自动发一个pdf传真传真服务器并且传真的问题