public bool SendEmailPurchaseOrder(OrderSendEmail obj) { var supplierDetails = GetSupplierEmails(obj.SupplierName, 1); ILog _logger = LogManager.GetLogger(typeof(OrderSendEmailDAL)); var xeroInVoice = getXeroDTSID(obj.PurchaseOrderId); var body = "Hi , <br/> Please process the attached order."; var subject = "Deltone Solutions Order " + xeroInVoice; var contactID = Convert.ToInt32(getContactID(obj.PurchaseOrderId)); var companyName = GetCompanybyContactID(contactID); if (supplierDetails.Count() > 0) { var toAddress = supplierDetails[0].SupplierEmailAddress; var ccAddress = ""; // var toAddress = "*****@*****.**"; foreach (var item in supplierDetails.Skip(1)) { if (ccAddress == "") { ccAddress = item.SupplierEmailAddress; } else { ccAddress = ccAddress + "," + item.SupplierEmailAddress; } } var bodyMessageCom = " <br/> Delivery Type : " + obj.OrderType; body = body + bodyMessageCom; if (!string.IsNullOrEmpty(obj.EmailBody)) { body = body + " <br/> Instructions : " + obj.EmailBody; } var bccAddress = DelToneCommonSettings.bccInfoAddress; var fromName = DelToneCommonSettings.fromName; var fromAddress = DelToneCommonSettings.fromAddress; var invoiceFilePath = DelToneCommonSettings.fileInvoicePath; var invoiceAusJetPath = DelToneCommonSettings.fileCSVPath; var files = obj.FileNames.Split(','); var attachements = new List <Attachment>(); var comFilePath = ""; var invoiceFileName = obj.SupplierName + "-" + xeroInVoice + "-" + companyName + ".pdf"; var invoiceFile = invoiceFilePath + invoiceFileName; if (File.Exists(invoiceFile)) { System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(invoiceFile); attachment.Name = invoiceFileName; attachements.Add(attachment); } if (obj.SupplierName == "Ausjet") { var csvFile = "AUSJET - Order " + xeroInVoice + ".csv"; comFilePath = invoiceAusJetPath + csvFile; if (File.Exists(comFilePath)) { System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(comFilePath); attachment.Name = csvFile; attachements.Add(attachment); } } //foreach (var file in files) //{ // var fIem = file; // if (obj.SupplierName == "Ausjet") // { // comFilePath = invoiceFilePath + fIem; // if (File.Exists(comFilePath)) // { // System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(comFilePath); // attachment.Name = fIem; // attachements.Add(attachment); // } // else // { // comFilePath = invoiceAusJetPath + fIem; // if (File.Exists(comFilePath)) // { // System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(comFilePath); // attachment.Name = fIem; // attachements.Add(attachment); // } // } // } // else // { // comFilePath = invoiceFilePath + fIem; // if (File.Exists(comFilePath)) // { // System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(comFilePath); // attachment.Name = fIem; // attachements.Add(attachment); // } // } //} var sendEmail = new EmailSender(); try { var resultSend = sendEmail.SendEmail(fromAddress, fromName, toAddress, ccAddress, bccAddress, subject, body, true, attachements); if (resultSend) { _logger.Info(" Email Sent Success :" + toAddress + " Order Id: " + obj.PurchaseOrderId + " Xero Dts: " + xeroInVoice); } else { _logger.Info(" Email Sent Error : " + toAddress + " Order Id: " + obj.PurchaseOrderId + " Xero Dts: " + xeroInVoice); } return(resultSend); } catch (Exception ex) { _logger.Error(" Error Occurred :" + ex + " Email Sent " + toAddress + " Order Id: " + obj.PurchaseOrderId + " Xero Dts: " + xeroInVoice); return(false); } } return(false); }