public int AddEmailOut(EmailOutDataSet sysParameter) { int newId = -1; try { if (emailConn.State != System.Data.ConnectionState.Open) { emailConn.Open(); } SqlCommand cmd = emailConn.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "spAddEmailOut"; var p2 = new SqlParameter[12]; for (int i = 0; i < 12; i++) { p2[i] = new SqlParameter(); } p2[0] = new SqlParameter("senderName", sysParameter.EmailOut[0].SenderName); p2[1] = new SqlParameter("subject", sysParameter.EmailOut[0].Subject); p2[2] = new SqlParameter("recipient", sysParameter.EmailOut[0].Recipient); p2[3] = new SqlParameter("cc", sysParameter.EmailOut[0].CC); p2[4] = new SqlParameter("bcc", sysParameter.EmailOut[0].BCC); p2[5] = new SqlParameter("message", sysParameter.EmailOut[0].Message); p2[6] = new SqlParameter("gatewayId", sysParameter.EmailOut[0].GatewayId); p2[7] = new SqlParameter("attachments", sysParameter.EmailOut[0].Attachments); p2[8] = new SqlParameter("status", sysParameter.EmailOut[0].Status); p2[9] = new SqlParameter("errorCode", sysParameter.EmailOut[0].ErrorCode); p2[10] = new SqlParameter("e_datetime", sysParameter.EmailOut[0].EDateTime); p2[11] = new SqlParameter("s_datetime", sysParameter.EmailOut[0].SDateTime); cmd.Parameters.AddRange(p2); newId = int.Parse(cmd.ExecuteScalar().ToString()); } catch (Exception ex) { throw; } finally { if (emailConn.State != System.Data.ConnectionState.Closed) { emailConn.Close(); } } return(newId); }
public static void CreateEmails() { try { var dataProvider = new DataProvider(); var alertEmails = dataProvider.GetEventAlertEmailsByDate(DateTime.Now); if (alertEmails.Email.Count > 0) { try { Console.WriteLine(alertEmails.Email.Count + " emails to send"); logger.Log(Level.INFO, alertEmails.Email.Count + " emails to send"); foreach (var email in alertEmails.Email) { dataProvider.MarkMessageAsProcessed(true, email.Id); string body = email.Body; string subject = email.Subject; body = body.Replace("[Event Name]", email.Event); body = body.Replace("[Location]", email.Location); body = body.Replace("[Location]", email.Location); body = body.Replace("[Begin Time]", DateTime.Parse(email.BeginTime.ToString()).ToString("h:mm tt")); body = body.Replace("[Begin Date]", email.BeginDate.ToLongDateString()); body = body.Replace("[Site URL]", "WWW.IGNITE.COM"); body = body.Replace("[End Date]", email.EndDate.ToLongDateString()); body = body.Replace("[End Time]", DateTime.Parse(email.EndTime.ToString()).ToString("h:mm tt")); subject = subject.Replace("[Event Name]", email.Event); subject = subject.Replace("[Location]", email.Location); subject = subject.Replace("[Location]", email.Location); subject = subject.Replace("[Begin Time]", DateTime.Parse(email.BeginTime.ToString()).ToString("h:mm tt")); subject = subject.Replace("[Begin Date]", email.BeginDate.ToLongDateString()); subject = subject.Replace("[Site URL]", "WWW.IGNITE.COM"); subject = subject.Replace("[End Date]", email.EndDate.ToLongDateString()); subject = subject.Replace("[End Time]", DateTime.Parse(email.EndTime.ToString()).ToString("h:mm tt")); if (body.Contains("[Price]")) { var dicPrices = dataProvider.GetTicketPriceByEventId(email.EventId); string strPrice = ""; foreach (var price in dicPrices) { strPrice += "\n\n" + price.Value + " - " + price.Key; } body = body.Replace("[Price]", strPrice); } if (subject.Contains("[Price]")) { var dicPrices = dataProvider.GetTicketPriceByEventId(email.EventId); string strPrice = ""; foreach (var price in dicPrices) { strPrice += " " + price.Value + " - " + price.Key; } subject = subject.Replace("[Price]", strPrice); } if (email.isUser) { Dictionary <string, string> users = dataProvider.GetCustomerDetailsByEventId(email.EventId); foreach (var user in users) { logger.Log(Level.DEBUG, string.Format("Processing Email to '{0}' ", user.Value)); Console.WriteLine(String.Format("Processing Email to '{0}' ", user.Value)); body = body.Replace("[Recipient Name]", user.Key); EmailOutDataSet ds = new EmailOutDataSet(); ds.EmailOut.AddEmailOutRow(1, email.Organisation, subject, user.Value, string.Empty, string.Empty, body, gatewayId, string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now); int result = dataProvider.AddEmailOut(ds); if (result != -1) { logger.Log(Level.DEBUG, string.Format("Email to '{0}' sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' sent.", user.Value)); } else { logger.Log(Level.DEBUG, string.Format("Email to '{0}' not sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' not sent.", user.Value)); } } } else { Dictionary <string, string> users = dataProvider.GetEventCoordinatorDetailsByEventId(email.EventId); foreach (var user in users) { logger.Log(Level.DEBUG, string.Format("Processing Email to '{0}' ", user.Value)); Console.WriteLine(String.Format("Processing Email to '{0}' ", user.Value)); body = body.Replace("[Recipient Name]", user.Key); EmailOutDataSet ds = new EmailOutDataSet(); ds.EmailOut.AddEmailOutRow(1, email.Organisation, email.Subject, user.Value, string.Empty, string.Empty, body, gatewayId, string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now); int result = dataProvider.AddEmailOut(ds); if (result != -1) { logger.Log(Level.DEBUG, string.Format("Email to '{0}' sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' sent.", user.Value)); } else { logger.Log(Level.DEBUG, string.Format("Email to '{0}' not sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' not sent.", user.Value)); } } } } } catch (Exception ex) { logger.Log(Level.ERROR, ex.Message); Console.WriteLine(ex.Message); } finally { is_running = true; } logger.Log(Level.INFO, "Processing Emails completed \n"); Console.WriteLine("Processing Emails completed \n"); } } catch (Exception ex) { logger.Log(Level.ERROR, ex.Message); Console.WriteLine(ex.Message); } finally { is_running = true; } }
public static void CreateEmails() { try { var dataProvider = new DataProvider(); var alertEmails = dataProvider.GetEventAlertEmailsByDate(DateTime.Now); if (alertEmails.Email.Count > 0) { try { Console.WriteLine(alertEmails.Email.Count + " emails to send"); logger.Log(Level.INFO, alertEmails.Email.Count + " emails to send"); foreach (var email in alertEmails.Email) { dataProvider.MarkMessageAsProcessed(true,email.Id); string body = email.Body; string subject = email.Subject; body = body.Replace("[Event Name]", email.Event); body = body.Replace("[Location]", email.Location); body = body.Replace("[Location]", email.Location); body = body.Replace("[Begin Time]", DateTime.Parse(email.BeginTime.ToString()).ToString("h:mm tt")); body = body.Replace("[Begin Date]", email.BeginDate.ToLongDateString()); body = body.Replace("[Site URL]", "WWW.IGNITE.COM"); body = body.Replace("[End Date]", email.EndDate.ToLongDateString()); body = body.Replace("[End Time]", DateTime.Parse(email.EndTime.ToString()).ToString("h:mm tt")); subject = subject.Replace("[Event Name]", email.Event); subject = subject.Replace("[Location]", email.Location); subject = subject.Replace("[Location]", email.Location); subject = subject.Replace("[Begin Time]", DateTime.Parse(email.BeginTime.ToString()).ToString("h:mm tt")); subject = subject.Replace("[Begin Date]", email.BeginDate.ToLongDateString()); subject = subject.Replace("[Site URL]", "WWW.IGNITE.COM"); subject = subject.Replace("[End Date]", email.EndDate.ToLongDateString()); subject = subject.Replace("[End Time]", DateTime.Parse(email.EndTime.ToString()).ToString("h:mm tt")); if (body.Contains("[Price]")) { var dicPrices = dataProvider.GetTicketPriceByEventId(email.EventId); string strPrice = ""; foreach (var price in dicPrices) { strPrice += "\n\n" +price.Value + " - " + price.Key; } body = body.Replace("[Price]", strPrice); } if (subject.Contains("[Price]")) { var dicPrices = dataProvider.GetTicketPriceByEventId(email.EventId); string strPrice = ""; foreach (var price in dicPrices) { strPrice += " " + price.Value + " - " + price.Key; } subject = subject.Replace("[Price]", strPrice); } if (email.isUser) { Dictionary<string, string> users = dataProvider.GetCustomerDetailsByEventId(email.EventId); foreach (var user in users) { logger.Log(Level.DEBUG, string.Format("Processing Email to '{0}' ", user.Value)); Console.WriteLine(String.Format("Processing Email to '{0}' ", user.Value)); body = body.Replace("[Recipient Name]",user.Key); EmailOutDataSet ds = new EmailOutDataSet(); ds.EmailOut.AddEmailOutRow(1, email.Organisation,subject, user.Value, string.Empty, string.Empty, body, gatewayId, string.Empty,0, string.Empty, DateTime.Now, DateTime.Now); int result = dataProvider.AddEmailOut(ds); if (result != -1) { logger.Log(Level.DEBUG, string.Format("Email to '{0}' sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' sent.", user.Value)); } else { logger.Log(Level.DEBUG, string.Format("Email to '{0}' not sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' not sent.", user.Value)); } } } else { Dictionary<string, string> users = dataProvider.GetEventCoordinatorDetailsByEventId(email.EventId); foreach (var user in users) { logger.Log(Level.DEBUG, string.Format("Processing Email to '{0}' ", user.Value)); Console.WriteLine(String.Format("Processing Email to '{0}' ", user.Value)); body = body.Replace("[Recipient Name]", user.Key); EmailOutDataSet ds = new EmailOutDataSet(); ds.EmailOut.AddEmailOutRow(1, email.Organisation, email.Subject, user.Value, string.Empty, string.Empty, body, gatewayId, string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now); int result = dataProvider.AddEmailOut(ds); if (result != -1) { logger.Log(Level.DEBUG, string.Format("Email to '{0}' sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' sent.", user.Value)); } else { logger.Log(Level.DEBUG, string.Format("Email to '{0}' not sent.", user.Value)); Console.WriteLine(String.Format("Email to '{0}' not sent.", user.Value)); } } } } } catch (Exception ex) { logger.Log(Level.ERROR, ex.Message); Console.WriteLine(ex.Message); } finally { is_running = true; } logger.Log(Level.INFO, "Processing Emails completed \n"); Console.WriteLine("Processing Emails completed \n"); } } catch (Exception ex) { logger.Log(Level.ERROR, ex.Message); Console.WriteLine(ex.Message); } finally { is_running = true; } }
public int AddEmailOut(EmailOutDataSet sysParameter) { int newId = -1; try { if (emailConn.State != System.Data.ConnectionState.Open) { emailConn.Open(); } SqlCommand cmd = emailConn.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "spAddEmailOut"; var p2 = new SqlParameter[12]; for (int i = 0; i < 12; i++) p2[i] = new SqlParameter(); p2[0] = new SqlParameter("senderName", sysParameter.EmailOut[0].SenderName); p2[1] = new SqlParameter("subject", sysParameter.EmailOut[0].Subject); p2[2] = new SqlParameter("recipient", sysParameter.EmailOut[0].Recipient); p2[3] = new SqlParameter("cc", sysParameter.EmailOut[0].CC); p2[4] = new SqlParameter("bcc", sysParameter.EmailOut[0].BCC); p2[5] = new SqlParameter("message", sysParameter.EmailOut[0].Message); p2[6] = new SqlParameter("gatewayId", sysParameter.EmailOut[0].GatewayId); p2[7] = new SqlParameter("attachments", sysParameter.EmailOut[0].Attachments); p2[8] = new SqlParameter("status", sysParameter.EmailOut[0].Status); p2[9] = new SqlParameter("errorCode", sysParameter.EmailOut[0].ErrorCode); p2[10] = new SqlParameter("e_datetime", sysParameter.EmailOut[0].EDateTime); p2[11] = new SqlParameter("s_datetime", sysParameter.EmailOut[0].SDateTime); cmd.Parameters.AddRange(p2); newId = int.Parse(cmd.ExecuteScalar().ToString()); } catch (Exception ex) { throw; } finally { if (emailConn.State != System.Data.ConnectionState.Closed) { emailConn.Close(); } } return newId; }
protected void btnSend_OnClick(object sender, EventArgs e) { if (!(txtMessage.Text.Length > 0) || !(txtSubject.Text.Length > 0)) { SetToast("error", "Fill out all fields!"); return; } var emailOut = new EmailOutDataSet(); Dictionary <string, string> recipients = new Dictionary <string, string>(); try { switch (int.Parse(cbRecipients.SelectedValue)) { case 0: recipients = dataProvider.GetAllOwnerOrgEmail(); break; case 1: recipients = dataProvider.GetAllAdminUserEmail(); break; case 2: recipients = dataProvider.GetAllCustomerEmail(); break; case 3: recipients = dataProvider.GetAllOwnerOrgEmailByCategory(int.Parse(cbFilter.SelectedValue)); break; case 4: recipients = dataProvider.GetAllCustomerEmailByInterest(int.Parse(cbFilter.SelectedValue)); break; default: return; } } catch (Exception ex) { SetToast("error", "An error occured, try again."); } string body = txtMessage.Text; try { foreach (var recipient in recipients) { body = body.Replace("[Recipient Name]", recipient.Key); emailOut.EmailOut.AddEmailOutRow(0, Utilities.companyName, txtSubject.Text, recipient.Value, string.Empty, string.Empty, body, gatewayId, string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now); dataProvider.AddEmailOut(emailOut); } SetToast("success", "Message Sent!"); } catch (Exception ex) { SetToast("error", "An error occured."); } }
protected void btnSend_OnClick(object sender, EventArgs e) { if (!(txtMessage.Text.Length > 0) || !(txtSubject.Text.Length > 0)) { SetToast("error","Fill out all fields!"); return; } var emailOut = new EmailOutDataSet(); Dictionary<string,string> recipients = new Dictionary<string, string>(); try { switch (int.Parse(cbRecipients.SelectedValue)) { case 0: recipients = dataProvider.GetAllOwnerOrgEmail(); break; case 1: recipients = dataProvider.GetAllAdminUserEmail(); break; case 2: recipients = dataProvider.GetAllCustomerEmail(); break; case 3: recipients = dataProvider.GetAllOwnerOrgEmailByCategory(int.Parse(cbFilter.SelectedValue)); break; case 4: recipients = dataProvider.GetAllCustomerEmailByInterest(int.Parse(cbFilter.SelectedValue)); break; default: return; } } catch (Exception ex) { SetToast("error","An error occured, try again."); } string body = txtMessage.Text; try { foreach (var recipient in recipients) { body = body.Replace("[Recipient Name]", recipient.Key); emailOut.EmailOut.AddEmailOutRow(0, Utilities.companyName, txtSubject.Text, recipient.Value, string.Empty, string.Empty, body, gatewayId, string.Empty, 0, string.Empty, DateTime.Now, DateTime.Now); dataProvider.AddEmailOut(emailOut); } SetToast("success","Message Sent!"); } catch (Exception ex) { SetToast("error","An error occured."); } }