//this function is used for mail. void Mailer(String FromMail,string Report) { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Mailer for Payment Reversal Report"); DateTime yesterday = DateTime.Now.AddDays(-1); string tracedate = yesterday.ToString("MM/dd/yyyy"); string[] dateYesterday = tracedate.Split('/'); string date = dateYesterday[1].ToString(); string Month = dateYesterday[0].ToString(); string Year = dateYesterday[2].ToString(); //date is converted according to the date of sql data. string dateDB = Year + "-" + Month + "-" + date; Mail objMail = new Mail(); MailData objmaildata = new MailData(); objmaildata.from = ConfigurationManager.AppSettings["Emailfrom"]; objmaildata.fromName = ""; objmaildata.to = FromMail.ToString(); objmaildata.toName = ""; if (Report == "Report") objmaildata.subject =dateDB+" "+"Payment Reversal Report"; if (Report =="Detailed Report") objmaildata.subject = dateDB + " " +"Detailed Payment Reversal Report"; string BodyMaggage = null; if (Report == "Report") { //this the body of mail. BodyMaggage = "<div>" + "<p>Dear Sir<br/></p>" + "<p>Please find the Yesterday's Daily Report of payment reversal.</p>" + "<p>Regards</p><p>KOD TEAM</p>" + "</div>" ; } if (Report == "Detailed Report") { //this the body of mail. BodyMaggage = "<div>" + "<p>Dear Sir<br/></p>" + "<p>Please find the Yesterday's Detailed Daily Report of payment reversal.</p>" + "<p>Regards</p><p>KOD TEAM</p>" + "</div>" ; } objmaildata.bodyMessage = BodyMaggage; if (Report =="Report") objMail.sendMail_Net(objmaildata,"Report"); if (Report =="Detailed Report") objMail.sendMail_Net(objmaildata,"Detailed Report"); }
//sends a mail public void sendMail_Net(MailData aMail, string Report) { MailMessage oMsg = new MailMessage(); // Set the message sender oMsg.From = new MailAddress(aMail.from, aMail.fromName); // The .To property is a generic collection, // so we can add as many recipients as we like. oMsg.To.Add(new MailAddress(aMail.to, aMail.toName)); //if the mail is sent with cc in recipients if (aMail.CCto != null) { if (aMail.CCto.Contains(";")) { string[] mailarr = aMail.CCto.Split(';'); for (int i = 0; i < mailarr.Length; i++) { oMsg.CC.Add(mailarr[i]); } } else { oMsg.CC.Add(aMail.CCto); } } Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Find Attachment for Report "); DateTime yesterday = DateTime.Now.AddDays(-1); string tracedate = yesterday.ToString("MM/dd/yyyy"); string[] dateYesterday = tracedate.Split('/'); string date = dateYesterday[1].ToString(); string Month = dateYesterday[0].ToString(); string Year = dateYesterday[2].ToString(); string dateDB = Year + "-" + Month + "-" + date; if (Report == "Report") { ReportPath = ConfigurationManager.AppSettings["DetailedReportPath"] + dateDB + ".xls"; } if (Report == "Detailed Report") { ReportPath = ConfigurationManager.AppSettings["DetailedReportPath_Detailed"] + dateDB + ".xls"; } //collect the attachment for the mail. if (File.Exists(ReportPath)) { Attachment mail = new Attachment(ReportPath); oMsg.Attachments.Add(mail); } else { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("There are no file to attach for Report "); } Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Collect all Attachment for Report "); // Set the content //Subject of the mail oMsg.Subject = aMail.subject; //Body of the mail oMsg.Body = aMail.bodyMessage; //set if the mail is html or not oMsg.IsBodyHtml = true; SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 25); oSmtp.EnableSsl = true; System.Net.NetworkCredential credentials = new NetworkCredential("*****@*****.**", "k1ngd0m2012"); oSmtp.UseDefaultCredentials = false; oSmtp.Credentials = credentials; oSmtp.Timeout = 50000000; try { oSmtp.Send(oMsg); Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Mail sent for Payment Reversal Report "); } catch (Exception ex) { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Exception while sending a mail " + ex); } finally { } //release the file for next process. oMsg.Attachments.Dispose(); }
//sends a mail public void sendMail_Net(MailData aMail,string Report) { MailMessage oMsg = new MailMessage(); // Set the message sender oMsg.From = new MailAddress(aMail.from, aMail.fromName); // The .To property is a generic collection, // so we can add as many recipients as we like. oMsg.To.Add(new MailAddress(aMail.to, aMail.toName)); //if the mail is sent with cc in recipients if (aMail.CCto != null) { if (aMail.CCto.Contains(";")) { string[] mailarr = aMail.CCto.Split(';'); for (int i = 0; i < mailarr.Length; i++) oMsg.CC.Add(mailarr[i]); } else oMsg.CC.Add(aMail.CCto); } Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Find Attachment for Report "); DateTime yesterday = DateTime.Now.AddDays(-1); string tracedate = yesterday.ToString("MM/dd/yyyy"); string[] dateYesterday = tracedate.Split('/'); string date = dateYesterday[1].ToString(); string Month = dateYesterday[0].ToString(); string Year = dateYesterday[2].ToString(); string dateDB = Year + "-" + Month + "-" + date; if(Report=="Report") ReportPath = ConfigurationManager.AppSettings["DetailedReportPath"]+dateDB+".xls"; if (Report == "Detailed Report") ReportPath = ConfigurationManager.AppSettings["DetailedReportPath_Detailed"] + dateDB + ".xls"; //collect the attachment for the mail. if (File.Exists(ReportPath)) { Attachment mail = new Attachment(ReportPath); oMsg.Attachments.Add(mail); } else { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("There are no file to attach for Report "); } Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Collect all Attachment for Report "); // Set the content //Subject of the mail oMsg.Subject = aMail.subject; //Body of the mail oMsg.Body = aMail.bodyMessage; //set if the mail is html or not oMsg.IsBodyHtml = true; SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 25); oSmtp.EnableSsl = true; System.Net.NetworkCredential credentials = new NetworkCredential("*****@*****.**", "k1ngd0m2012"); oSmtp.UseDefaultCredentials = false; oSmtp.Credentials = credentials; oSmtp.Timeout = 50000000; try { oSmtp.Send(oMsg); Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Mail sent for Payment Reversal Report "); } catch (Exception ex) { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Exception while sending a mail " + ex); } finally { } //release the file for next process. oMsg.Attachments.Dispose(); }
//this function is used for mail. void Mailer(String FromMail, string Report) { Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Mailer for Payment Reversal Report"); DateTime yesterday = DateTime.Now.AddDays(-1); string tracedate = yesterday.ToString("MM/dd/yyyy"); string[] dateYesterday = tracedate.Split('/'); string date = dateYesterday[1].ToString(); string Month = dateYesterday[0].ToString(); string Year = dateYesterday[2].ToString(); //date is converted according to the date of sql data. string dateDB = Year + "-" + Month + "-" + date; Mail objMail = new Mail(); MailData objmaildata = new MailData(); objmaildata.from = ConfigurationManager.AppSettings["Emailfrom"]; objmaildata.fromName = ""; objmaildata.to = FromMail.ToString(); objmaildata.toName = ""; if (Report == "Report") { objmaildata.subject = dateDB + " " + "Payment Reversal Report"; } if (Report == "Detailed Report") { objmaildata.subject = dateDB + " " + "Detailed Payment Reversal Report"; } string BodyMaggage = null; if (Report == "Report") { //this the body of mail. BodyMaggage = "<div>" + "<p>Dear Sir<br/></p>" + "<p>Please find the Yesterday's Daily Report of payment reversal.</p>" + "<p>Regards</p><p>KOD TEAM</p>" + "</div>" ; } if (Report == "Detailed Report") { //this the body of mail. BodyMaggage = "<div>" + "<p>Dear Sir<br/></p>" + "<p>Please find the Yesterday's Detailed Daily Report of payment reversal.</p>" + "<p>Regards</p><p>KOD TEAM</p>" + "</div>" ; } objmaildata.bodyMessage = BodyMaggage; if (Report == "Report") { objMail.sendMail_Net(objmaildata, "Report"); } if (Report == "Detailed Report") { objMail.sendMail_Net(objmaildata, "Detailed Report"); } }