Email via C# Blank Title 127619

  Private Sub SendEmail(ByVal pro as DataTable)
   
        dim info as string()
   
            'send e-mails...
        dim comp as new Epicor.Mfg.BO.Company(oTrans.Session.ConnectionPool)
        dim compDS as Epicor.Mfg.BO.CompanyDataSet = comp.GetByID(oTrans.Session.CompanyID)       
        dim client as new SmtpClient(compDS.Company(0).SmtpServer, compDS.Company(0).SmtpPort)
       
        'Dim SmtpUser As New System.Net.NetworkCredential()

        'setup the domain credentials
        'SmtpUser.Domain = EmailDomain
        'SmtpUser.Password = EmailPassword
        'SmtpUser.UserName = EmailUserName

        'set the domain credentials to the smtp object
        client.UseDefaultCredentials = True
        'client.Credentials = SmtpUser
       
        dim mail as MailMessage = new MailMessage(compDS.Company(0).EmailFromAddr, EmailTo)
       
        mail.Subject = EmailSubject
        mail.IsBodyHtml = true
       
        dim sb as new System.Text.StringBuilder()
       
        if pro.Select("OrderNum > 0").Length > 0 then
            sb.Append("The following orders were genereted by the SO Inbound Process:<br /><br />")
           
            dim dv as new DataView(pro)
            dv.RowFilter = "OrderNum > 0"
            for each dr as DataRow in dv.ToTable(true, "OrderNum".Split(",")).Rows
                sb.Append(dr("OrderNum").ToString()).Append("<br />")
            next
           
        end if
       
        if errors.Count > 0 then
            sb.Append("<br /><br />There were some errors while attempting to import some of the data. Attached is also a file with the error lines.  Please correct the errors in the file and place into the processing directory to re-process the lines. Please see below for further information:<br /><br />")
            sb.Append("<table><tr><td><b>Part Number</b></td><td><b>Line</b></td><td><b>File Name</b></td><td><b>Error</b></td></tr>")         
           
            for each str as string in errors
                info = str.Split("~")
               
                sb.Append("<tr><td>").Append(info(0)).Append("</td><td>").Append(info(1)).Append("</td><td>").Append(info(2)).Append("</td><td>").Append(info(3)).Append("</td></tr>")
            next
           
            sb.Append("</table>")
       
            dim bad as new System.Text.StringBuilder()
       
            bad.Append("Customercode,WhseCode,ErpPo,Partnumber,QtyOrdered,Line,OrderedPrice,NeedBy,ShipBy,ErrorReason")           
       
            for each dr as DataRow in pro.Select("OrderNum = 0")
                bad.Append(vbCrLf).Append(dr("CustID").ToString()).Append(",").Append(dr("Warehouse").ToString()).Append(",").Append(dr("PO").ToString()).Append(",")
                bad.Append(dr("PartNum").ToString()).Append(",").Append(dr("Qty").ToString()).Append(",").Append(dr("Line").ToString()).Append(",")
                bad.Append(dr("Price").ToString()).Append(",")
                try
                    bad.Append(DateTime.Parse(dr("NeedBy").ToString()).ToString("MM/dd/yyyy")).Append(",")
                catch
                    bad.Append(",")
                end try
               
                try
                    bad.Append(DateTime.Parse(dr("ShipBy").ToString()).ToString("MM/dd/yyyy")).Append(",")
                catch
                    bad.Append(",")
                end try
               
                bad.Append("""").Append(dr("ErrorReason").ToString()).Append("""")             
               
            next
           
            Dim data As Byte() = Encoding.ASCII.GetBytes(bad.ToString())
           
            dim ms as New System.IO.MemoryStream(data)

            Dim attach As New System.Net.Mail.Attachment(ms, "SOInboundErrorFile-" + DateTime.Now.ToString("MM-dd-yyyy-hh-mm") + ".csv", "text/plain")

            mail.Attachments.Add(attach)
           
        end if
       
        mail.Body = sb.ToString()
       
        'if there are no rows, then do not send an e-mail
        if pro.Rows.Count > 0 then
            client.Send(mail)
        end if
   
    End Sub