public static void send(string Email, List <string> report, int id, IEnumerable <int> reportid) { //create the email message MailMessage mmAutomatedMessage = new MailMessage(); //create a reply to address mmAutomatedMessage.ReplyTo = new MailAddress("*****@*****.**"); //set the priority of the mail message to high to make sure it goes out at quickest possible speed mmAutomatedMessage.Priority = MailPriority.High; //put a read receipt on each report. Can monitor who is looking at their reports mmAutomatedMessage.Headers.Add("Disposition-Notification-To", "*****@*****.**"); //create From address mmAutomatedMessage.From = new MailAddress("*****@*****.**"); //[email protected] 20190611 string sendEmailsFrom = "*****@*****.**"; string sendEmailsFromPassword = "******"; //string sendEmailsFrom = "*****@*****.**"; //string sendEmailsFromPassword = "******"; NetworkCredential cred = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword); mmAutomatedMessage.To.Add(Email); //create subject mmAutomatedMessage.Subject = "Pro Automated Report" + " - " + DbContext.tbl_Portfoilolinks.Where(s => s.Protfolio_ID == id).Select(s => s.Protfolio_Name ?? "").SingleOrDefault(); //create the plain text version of the email string strBodyText = @"Dear Customer, Please open all image attachments prior to the HTML report in order to cache the charts. Please find enclosed your automated report as requested: Many Thanks, Pro Team Sentel Indepedant Ltd 15 Mckibbin House Eastbank Road Carryduff Belfast BT8 8BD T: +44 (0)28 9081 5555 F: +44 (0)28 9081 1055 E: [email protected] Keep up to date on http://www.sentel.co.uk Follow us on twitter at http://twitter.com/Sentel_Ind Follow us on facebook at http://www.facebook.com/pages/Belfast/Sentel-Independent/249597243565"; //create the media type for the plain text string strMediaType = "text/plain"; //create an alternative view AlternateView avPlainText = AlternateView.CreateAlternateViewFromString(strBodyText, null, strMediaType); //create the html version of the email strBodyText = @"<font face ='verdana' size='3'><p>Dear <b><i>Customer</i></b>,</p> <p>Please find enclosed your automated report as requested:</p> <p>Many Thanks,</p> <p><b>Pro Team</b></p> <p>Sentel <br />15 McKibbin House <br />Eastbank Road <br />Carryduff <br />Belfast <br />BT8 8BD </p> <p><font face ='verdana' size='2'>T: +44 (0)28 9081 5555 <br />F: +44 (0)28 9081 1055 <br />E: [email protected] </font> </p></font> <font face ='verdana' size='1'> <p> <a href='http://www.sentel.co.uk'>www.Sentel.co.uk</a> <br /><img src='http://www.sentelcallmanagerpro.com//images//SentelLogo.png' alt='Sentel' title='Sentel' /> </p> <p> Follow Sentel on Twitter <br /><img src='http://www.sentelcallmanagerpro.com//images//twitter.png' alt='Twitter' title='Twitter' /> <br />Ask us a question or keep up to date with our latest business news and events using Twitter <br /><a href='http://twitter.com/Sentel_Ind'>Sentel on Twitter</a> </p> <p> Follow Sentel on Facebook <br /><img src='http://www.sentelcallmanagerpro.com//images//facebook.png' alt='Facebook' title='FaceBook' /> <br />Add us to get all the latest upgrade news and developments on our products using Facebook <br /><a href='http://www.facebook.com/pages/Belfast/Sentel-Independent/249597243565'>Sentel on Facebook</a> </p> </font>"; //create the media type for the html strMediaType = "text/html"; //create an alternative view AlternateView avHTML = AlternateView.CreateAlternateViewFromString(strBodyText, null, strMediaType); //add both views to the collection mmAutomatedMessage.AlternateViews.Add(avPlainText); mmAutomatedMessage.AlternateViews.Add(avHTML); //Attache the report/error log try { Attachment attach; for (int i = 0; i < report.Count(); i++) { attach = new Attachment(report[i]); mmAutomatedMessage.Attachments.Add(attach); } SmtpClient client = new SmtpClient(MailClient); client.Timeout = 40000; client.Credentials = cred; client.Send(mmAutomatedMessage); DbContext.tbl_PortfolioReports.Where(s => s.PortfolioReport_Email == Email).ToList().ForEach(s => s.PortfolioReport_Status = true); DbContext.SubmitChanges(); } catch { foreach (int v in reportid) { GenerateReports.ReportStatus(v, "ErrEmail"); } } //ProgressText.Append("Email sent to '" + Email + "'. Completed \r\n"); //tbProgress.Text = ProgressText.ToString(); ; }
public static void Undoreport(Schedule report) { try { DateTime From = DateTime.Now, To = DateTime.Now; try { From = Convert.ToDateTime(report.ListofFilters.Split('=', ',')[5].TrimStart('\'').TrimEnd('\'')); To = Convert.ToDateTime(report.ListofFilters.Split('=', ',')[7].TrimStart('\'').TrimEnd('\'')); } catch { } string inter = ""; switch (report.Frequency) { case "hourly": if (Starttime != 17) { inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + To.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); } else { inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddHours(16).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + To.AddHours(16).ToString("yyyy-MM-dd HH:mm:ss") + "'"); } break; case "fixed": inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + To.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); break; case "daily": inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + To.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); break; case "weekly": inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + To.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss") + "'"); break; case "monthly": inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + From.AddMonths(-2).AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); break; case "quaterly": inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddMonths(-3).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + From.AddMonths(-3).AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.CreatedDate = report.CreatedDate.AddMonths(3); break; case "yearly": inter = report.ListofFilters.Replace(report.ListofFilters.Split('=', ',')[5], "'" + From.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); report.ListofFilters = inter.Replace(report.ListofFilters.Split('=', ',')[7], "'" + To.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'"); break; } // Need an update statement here..... var rep = DbContext.tbl_automatedreports.Where(s => s.schedule_id_PK == report.ID).SingleOrDefault(); rep.schedule_filters = report.ListofFilters; rep.schedule_createddate = report.CreatedDate; DbContext.SubmitChanges(); } catch { GenerateReports.ReportStatus(report.ID, "Erro Updating Report"); } }