/// <summary> /// Populates the fields for multiple objects from the columns found in an open reader. /// </summary> /// /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param> /// /// <returns>Object of MailApprovals</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 12/17/2012 12:22:55 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// internal static MailApprovals PopulateObjectsFromReaderWithCheckingReader(IDataReader rdr, DatabaseHelper oDatabaseHelper, string ConnectionString) { MailApprovals list = new MailApprovals(); if (rdr.Read()) { MailApproval obj = new MailApproval(ConnectionString); PopulateObjectFromReader(obj, rdr); list.Add(obj); while (rdr.Read()) { obj = new MailApproval(ConnectionString); PopulateObjectFromReader(obj, rdr); list.Add(obj); } oDatabaseHelper.Dispose(); return list; } else { oDatabaseHelper.Dispose(); return null; } }
/// <summary> /// Populates the fields for multiple objects from the columns found in an open reader. /// </summary> /// /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param> /// /// <returns>Object of MailApprovals</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 12/17/2012 12:22:55 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// internal static MailApprovals PopulateObjectsFromReader(IDataReader rdr, string ConnectionString) { MailApprovals list = new MailApprovals(); while (rdr.Read()) { MailApproval obj = new MailApproval(ConnectionString); PopulateObjectFromReader(obj,rdr); list.Add(obj); } return list; }
/// <summary> /// This method will return an object representing the record matching the primary key information specified. /// </summary> /// /// <param name="pk" type="MailApprovalPrimaryKey">Primary Key information based on which data is to be fetched.</param> /// /// <returns>object of class MailApproval</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 12/17/2012 12:22:55 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// public static MailApproval SelectOne(MailApprovalPrimaryKey pk,string ConnectionString) { DatabaseHelper oDatabaseHelper = new DatabaseHelper(); bool ExecutionState = false; // Pass the values of all key parameters to the stored procedure. System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues(); foreach (string key in nvc.Keys) { oDatabaseHelper.AddParameter("@" + key,nvc[key] ); } // The parameter '@ErrorCode' will contain the status after execution of the stored procedure. oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output); IDataReader dr=oDatabaseHelper.ExecuteReader("sp_MailApproval_SelectbyPrimaryKey", ref ExecutionState); if (dr.Read()) { MailApproval obj = new MailApproval(ConnectionString); PopulateObjectFromReader(obj,dr); dr.Close(); oDatabaseHelper.Dispose(); return obj; } else { dr.Close(); oDatabaseHelper.Dispose(); return null; } }
public XmlDocument LaunchMailingWithSuppressList(string UserID, string Password, string CampaignName, string Subject, string FromName, string ReplyToAddress, string FromAddress, DataSet Recipients, DataSet SuppressList, DataSet SeedList, string SchedulteDate, string sendType, string TemplateContent, string toReportMailID, string ApproverMailID) { string mailingId = string.Empty; string templateName = "SBTemplate" + DateTime.Now; StringBuilder mailContent = new StringBuilder(); mailContent.Append("<table width=\"700\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">"); //mailContent.Append("<tr><td align=\"left\" valign=\"top\" ><table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"-webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; border:solid #0167b5; border-width:1px 1px 1px 1px; background:#e8f3f7;\"><tr><td width=\"248\" align=\"left\" valign=\"top\" style=\"padding:5px;\"><img src=\"http://mta1.1pointinteractive.com/1Point/images/Logo-Login.png\" width=\"81\" height=\"44\" /></td><td width=\"250\" align=\"right\" valign=\"bottom\" style=\"padding:5px; font-family:arial; font-size:13px; color:#039; font-weight:bold;\">API Log Report_" + CampaignName + " </td></tr></table></td></tr>"); List<string> emailColumns = new List<string>(); emailColumns.Add("Email Address"); emailColumns.Add("emailaddress"); emailColumns.Add("email"); emailColumns.Add("e-mail"); emailColumns.Add("Email"); emailColumns.Add("e-mailaddress"); emailColumns.Add("emailaddress"); emailColumns.Add("emailadd"); emailColumns.Add("e-mailadd"); emailColumns.Add("emailaddress"); List<string> fnameColumns = new List<string>(); fnameColumns.Add("firstname"); fnameColumns.Add("first name"); fnameColumns.Add("fname"); List<string> lnameColumns = new List<string>(); lnameColumns.Add("lastname"); lnameColumns.Add("last name"); lnameColumns.Add("lname"); foreach (DataColumn clm in Recipients.Tables[0].Columns) { if (emailColumns.Contains(clm.ToString().ToLower())) Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress"; else if (fnameColumns.Contains(clm.ToString().ToLower())) Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName"; else if (lnameColumns.Contains(clm.ToString().ToLower())) Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "LastName"; } if (SuppressList != null && SuppressList.Tables.Count > 0) { foreach (DataColumn clm in SuppressList.Tables[0].Columns) { if (emailColumns.Contains(clm.ToString().ToLower())) SuppressList.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress"; else if (fnameColumns.Contains(clm.ToString().ToLower())) SuppressList.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName"; else if (lnameColumns.Contains(clm.ToString().ToLower())) SuppressList.Tables[0].Columns[clm.ToString()].ColumnName = "LastName"; } } if (SeedList != null && SeedList.Tables.Count > 0) { foreach (DataColumn clm in SeedList.Tables[0].Columns) { if (emailColumns.Contains(clm.ToString().ToLower())) SeedList.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress"; else if (fnameColumns.Contains(clm.ToString().ToLower())) SeedList.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName"; else if (lnameColumns.Contains(clm.ToString().ToLower())) SeedList.Tables[0].Columns[clm.ToString()].ColumnName = "LastName"; } } int subMailVertion = 1; StringBuilder str = new StringBuilder(); StringBuilder unDeleverdInfo = new StringBuilder(); str.Append("<MailingInfo>"); str.Append("<MailingList>"); try { string Con = GetConnectionString(UserID, Password); string validEmailIds = string.Empty; string unsubEmailIds = string.Empty; string hardBounceEmailIds = string.Empty; string softBounceEmailIds = string.Empty; string duplicateEmailids = string.Empty; DataTable contacts = Recipients.Tables[0]; Hashtable contatcInfo = new Hashtable(); if (Con.Trim().Length != 0) { LogStartInfo("LaunchMailingWithSuppressList", Con, UserID); Logger.logdata(logforRpService, "Input Paramiters :Camapign Name = " + CampaignName + "; No.of Contacts=" + Recipients.Tables[0].Rows.Count); if (!(contacts.Columns.IndexOf("EmailAddress") == -1)) { string QueryString = ""; #region Template TemplateMaster templateMaster = new TemplateMaster(Con); templateMaster.TemplateName = templateName; TemplateMasters tempMasters = TemplateMaster.SelectByField("TemplateName", templateName, Con); if (tempMasters.Count > 0) { str.Append("<Message>Template Name Already Existed</Message>"); //mailContent.Append("<tr><td colspan=\"2\">Template Name Already Existed</td></tr>"); } else { if (TemplateContent != "" && templateName != "") { TemplateContent = TemplateContent + "<br />If you no longer wish to receive these emails, simply click on the following link:<a href=\"[!RPLINK:GLOBALUNSUBSCRIBE!]\">Unsubscribe</a><br />"; templateMaster.HTMLContent = ExtractLinks(TemplateContent, Con); templateMaster.CreatedDate = DateTime.Now; int templateid = templateMaster.InsertReturnID(); //templateMaster.InsertWithDefaultValues(true); str.Append("<Message>Template Added Successfully</Message>"); //mailContent.Append("<tr><td colspan=\"2\">Template created successfully</td></tr>"); str.Append("<TemplateId>" + templateid.ToString() + "</TemplateId>"); //mailContent.Append("<tr><td>Template ID</td><td>" + templateid.ToString() + "</td></tr>"); //mailContent.Append("<tr><td>Template Name</td><td>" + templateName + "</td></tr>"); } else { str.Append("<Error>Please Enter Valid Inputs</Error>"); //mailContent.Append("<tr><td colspan=\"2\">No data found in uploaded template</td></tr>"); } } #endregion Int64 listid = 0, SupListId = 0, SeedListId = 0; ListMasterBase listMaster = null; #region TargetList if (contacts.Rows.Count > 0 && templateMaster != null) { string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray(); string eidsString = String.Join(",", EmailIds); Logger.logdata(logforRpService, "EmailIds from User :"******"<UndeliveredList>"); foreach (DataRow contact in contacts.Rows) { ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", contact["EmailAddress"].ToString(), Con); DataTable unSubDetails = new DataTable(); DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString()); if (contemail.Count > 0) { unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty); } if (unSubDetails.Rows.Count > 0) { unDeleverdInfo.Append("<Undelivered>"); if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub") { unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>"); unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";"; } else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain") { unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>"); hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";"; } unDeleverdInfo.Append("</Undelivered>"); } else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount) { unDeleverdInfo.Append("<Undelivered>"); unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>"); unDeleverdInfo.Append("</Undelivered>"); softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";"; } else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0) { try { if (contemail[0].IsActive == true) { QueryString = ""; for (int i = 0; i < contact.ItemArray.Length; i++) { QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!"; } if (!contatcInfo.ContainsKey(contemail[0].ContactId)) { contatcInfo.Add(contemail[0].ContactId, QueryString); validEmailIds = validEmailIds + contemail[0].EmailAddress + ";"; } else duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";"; ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString())); ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con); #region Handling Custom fields foreach (DataColumn column in contacts.Columns) { DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con); string custField = ""; if (customFieldDt.Rows.Count > 0) { custField = customFieldDt.Rows[0]["ContactFieldName"].ToString(); } else custField = column.ColumnName; if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString())) { switch (custField) { case "EmailAddress": objContactMaster.EmailAddress = contact[column.ColumnName].ToString(); break; case "FirstName": objContactMaster.FirstName = contact[column.ColumnName].ToString(); break; case "LastName": objContactMaster.LastName = contact[column.ColumnName].ToString(); break; case "Address1": objContactMaster.Address1 = contact[column.ColumnName].ToString(); break; case "City": objContactMaster.City = contact[column.ColumnName].ToString(); break; case "State": objContactMaster.State = contact[column.ColumnName].ToString(); break; case "PostalCode": objContactMaster.PostalCode = contact[column.ColumnName].ToString(); break; case "Country": objContactMaster.Country = contact[column.ColumnName].ToString(); break; case "WorkPhone": objContactMaster.WorkPhone = contact[column.ColumnName].ToString(); break; case "HomePhone": objContactMaster.HomePhone = contact[column.ColumnName].ToString(); break; case "MobilePhone": objContactMaster.MobilePhone = contact[column.ColumnName].ToString(); break; case "CustomField1": objContactMaster.CustomField1 = contact[column.ColumnName].ToString(); break; case "CustomField2": objContactMaster.CustomField2 = contact[column.ColumnName].ToString(); break; case "CustomField3": objContactMaster.CustomField3 = contact[column.ColumnName].ToString(); break; case "CustomField4": objContactMaster.CustomField4 = contact[column.ColumnName].ToString(); break; case "CustomField5": objContactMaster.CustomField5 = contact[column.ColumnName].ToString(); break; case "CustomField6": objContactMaster.CustomField6 = contact[column.ColumnName].ToString(); break; case "CustomField7": objContactMaster.CustomField7 = contact[column.ColumnName].ToString(); break; case "CustomField8": objContactMaster.CustomField8 = contact[column.ColumnName].ToString(); break; case "CustomField9": objContactMaster.CustomField9 = contact[column.ColumnName].ToString(); break; case "CustomField10": objContactMaster.CustomField10 = contact[column.ColumnName].ToString(); break; case "CustomField11": objContactMaster.CustomField11 = contact[column.ColumnName].ToString(); break; case "CustomField12": objContactMaster.CustomField12 = contact[column.ColumnName].ToString(); break; case "CustomField13": objContactMaster.CustomField13 = contact[column.ColumnName].ToString(); break; case "CustomField14": objContactMaster.CustomField14 = contact[column.ColumnName].ToString(); break; case "CustomField15": objContactMaster.CustomField15 = contact[column.ColumnName].ToString(); break; case "CustomField16": objContactMaster.CustomField16 = contact[column.ColumnName].ToString(); break; case "CustomField17": objContactMaster.CustomField17 = contact[column.ColumnName].ToString(); break; case "CustomField18": objContactMaster.CustomField18 = contact[column.ColumnName].ToString(); break; case "CustomField19": objContactMaster.CustomField19 = contact[column.ColumnName].ToString(); break; case "CustomField20": objContactMaster.CustomField20 = contact[column.ColumnName].ToString(); break; case "CustomField21": objContactMaster.CustomField21 = contact[column.ColumnName].ToString(); break; case "CustomField22": objContactMaster.CustomField22 = contact[column.ColumnName].ToString(); break; case "CustomField23": objContactMaster.CustomField23 = contact[column.ColumnName].ToString(); break; case "CustomField24": objContactMaster.CustomField24 = contact[column.ColumnName].ToString(); break; case "CustomField25": objContactMaster.CustomField25 = contact[column.ColumnName].ToString(); break; case "CustomField26": objContactMaster.CustomField26 = contact[column.ColumnName].ToString(); break; case "CustomField27": objContactMaster.CustomField27 = contact[column.ColumnName].ToString(); break; case "CustomField28": objContactMaster.CustomField28 = contact[column.ColumnName].ToString(); break; case "CustomField29": objContactMaster.CustomField29 = contact[column.ColumnName].ToString(); break; case "CustomField30": objContactMaster.CustomField30 = contact[column.ColumnName].ToString(); break; case "CustomField31": objContactMaster.CustomField31 = contact[column.ColumnName].ToString(); break; case "CustomField32": objContactMaster.CustomField32 = contact[column.ColumnName].ToString(); break; case "CustomField33": objContactMaster.CustomField33 = contact[column.ColumnName].ToString(); break; case "CustomField34": objContactMaster.CustomField34 = contact[column.ColumnName].ToString(); break; case "CustomField35": objContactMaster.CustomField35 = contact[column.ColumnName].ToString(); break; case "CustomField36": objContactMaster.CustomField36 = contact[column.ColumnName].ToString(); break; case "CustomField37": objContactMaster.CustomField37 = contact[column.ColumnName].ToString(); break; case "CustomField38": objContactMaster.CustomField38 = contact[column.ColumnName].ToString(); break; case "CustomField39": objContactMaster.CustomField39 = contact[column.ColumnName].ToString(); break; case "CustomField40": objContactMaster.CustomField40 = contact[column.ColumnName].ToString(); break; case "CustomField41": objContactMaster.CustomField41 = contact[column.ColumnName].ToString(); break; case "CustomField42": objContactMaster.CustomField42 = contact[column.ColumnName].ToString(); break; case "CustomField43": objContactMaster.CustomField43 = contact[column.ColumnName].ToString(); break; case "CustomField44": objContactMaster.CustomField44 = contact[column.ColumnName].ToString(); break; case "CustomField45": objContactMaster.CustomField45 = contact[column.ColumnName].ToString(); break; case "CustomField46": objContactMaster.CustomField46 = contact[column.ColumnName].ToString(); break; case "CustomField47": objContactMaster.CustomField47 = contact[column.ColumnName].ToString(); break; case "CustomField48": objContactMaster.CustomField48 = contact[column.ColumnName].ToString(); break; case "CustomField49": objContactMaster.CustomField49 = contact[column.ColumnName].ToString(); break; case "CustomField50": objContactMaster.CustomField50 = contact[column.ColumnName].ToString(); break; } } } #endregion if (objContactMaster.Update() == true) { //str.Append("<Message>Recipient Updated Successfully</Message>"); } else { //str.Append("<Error>Recipient Update Failed</Error>"); Logger.logdata(logforRpService, "Recipient Update Failed"); } } } catch (Exception ex) { str.Append("<Error>Edit Contact: Problem at updating contact</Error>"); Logger.logdata(logforRpService, "Update Contact :" + ex.Message); } } else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0) { try { ContactMaster objContactMaster = new ContactMaster(Con); objContactMaster.EmailAddress = contact["EmailAddress"].ToString(); objContactMaster.EmailContentType = "Html"; objContactMaster.CreatedDate = DateTime.Now; #region Handling Custom fields foreach (DataColumn column in contacts.Columns) { DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con); string custField = ""; if (customFieldDt.Rows.Count > 0) { custField = customFieldDt.Rows[0]["ContactFieldName"].ToString(); } else custField = column.ColumnName; if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString())) { switch (custField) { case "EmailAddress": objContactMaster.EmailAddress = contact[column.ColumnName].ToString(); break; case "FirstName": objContactMaster.FirstName = contact[column.ColumnName].ToString(); break; case "LastName": objContactMaster.LastName = contact[column.ColumnName].ToString(); break; case "Address1": objContactMaster.Address1 = contact[column.ColumnName].ToString(); break; case "City": objContactMaster.City = contact[column.ColumnName].ToString(); break; case "State": objContactMaster.State = contact[column.ColumnName].ToString(); break; case "PostalCode": objContactMaster.PostalCode = contact[column.ColumnName].ToString(); break; case "Country": objContactMaster.Country = contact[column.ColumnName].ToString(); break; case "WorkPhone": objContactMaster.WorkPhone = contact[column.ColumnName].ToString(); break; case "HomePhone": objContactMaster.HomePhone = contact[column.ColumnName].ToString(); break; case "MobilePhone": objContactMaster.MobilePhone = contact[column.ColumnName].ToString(); break; case "CustomField1": objContactMaster.CustomField1 = contact[column.ColumnName].ToString(); break; case "CustomField2": objContactMaster.CustomField2 = contact[column.ColumnName].ToString(); break; case "CustomField3": objContactMaster.CustomField3 = contact[column.ColumnName].ToString(); break; case "CustomField4": objContactMaster.CustomField4 = contact[column.ColumnName].ToString(); break; case "CustomField5": objContactMaster.CustomField5 = contact[column.ColumnName].ToString(); break; case "CustomField6": objContactMaster.CustomField6 = contact[column.ColumnName].ToString(); break; case "CustomField7": objContactMaster.CustomField7 = contact[column.ColumnName].ToString(); break; case "CustomField8": objContactMaster.CustomField8 = contact[column.ColumnName].ToString(); break; case "CustomField9": objContactMaster.CustomField9 = contact[column.ColumnName].ToString(); break; case "CustomField10": objContactMaster.CustomField10 = contact[column.ColumnName].ToString(); break; case "CustomField11": objContactMaster.CustomField11 = contact[column.ColumnName].ToString(); break; case "CustomField12": objContactMaster.CustomField12 = contact[column.ColumnName].ToString(); break; case "CustomField13": objContactMaster.CustomField13 = contact[column.ColumnName].ToString(); break; case "CustomField14": objContactMaster.CustomField14 = contact[column.ColumnName].ToString(); break; case "CustomField15": objContactMaster.CustomField15 = contact[column.ColumnName].ToString(); break; case "CustomField16": objContactMaster.CustomField16 = contact[column.ColumnName].ToString(); break; case "CustomField17": objContactMaster.CustomField17 = contact[column.ColumnName].ToString(); break; case "CustomField18": objContactMaster.CustomField18 = contact[column.ColumnName].ToString(); break; case "CustomField19": objContactMaster.CustomField19 = contact[column.ColumnName].ToString(); break; case "CustomField20": objContactMaster.CustomField20 = contact[column.ColumnName].ToString(); break; case "CustomField21": objContactMaster.CustomField21 = contact[column.ColumnName].ToString(); break; case "CustomField22": objContactMaster.CustomField22 = contact[column.ColumnName].ToString(); break; case "CustomField23": objContactMaster.CustomField23 = contact[column.ColumnName].ToString(); break; case "CustomField24": objContactMaster.CustomField24 = contact[column.ColumnName].ToString(); break; case "CustomField25": objContactMaster.CustomField25 = contact[column.ColumnName].ToString(); break; case "CustomField26": objContactMaster.CustomField26 = contact[column.ColumnName].ToString(); break; case "CustomField27": objContactMaster.CustomField27 = contact[column.ColumnName].ToString(); break; case "CustomField28": objContactMaster.CustomField28 = contact[column.ColumnName].ToString(); break; case "CustomField29": objContactMaster.CustomField29 = contact[column.ColumnName].ToString(); break; case "CustomField30": objContactMaster.CustomField30 = contact[column.ColumnName].ToString(); break; case "CustomField31": objContactMaster.CustomField31 = contact[column.ColumnName].ToString(); break; case "CustomField32": objContactMaster.CustomField32 = contact[column.ColumnName].ToString(); break; case "CustomField33": objContactMaster.CustomField33 = contact[column.ColumnName].ToString(); break; case "CustomField34": objContactMaster.CustomField34 = contact[column.ColumnName].ToString(); break; case "CustomField35": objContactMaster.CustomField35 = contact[column.ColumnName].ToString(); break; case "CustomField36": objContactMaster.CustomField36 = contact[column.ColumnName].ToString(); break; case "CustomField37": objContactMaster.CustomField37 = contact[column.ColumnName].ToString(); break; case "CustomField38": objContactMaster.CustomField38 = contact[column.ColumnName].ToString(); break; case "CustomField39": objContactMaster.CustomField39 = contact[column.ColumnName].ToString(); break; case "CustomField40": objContactMaster.CustomField40 = contact[column.ColumnName].ToString(); break; case "CustomField41": objContactMaster.CustomField41 = contact[column.ColumnName].ToString(); break; case "CustomField42": objContactMaster.CustomField42 = contact[column.ColumnName].ToString(); break; case "CustomField43": objContactMaster.CustomField43 = contact[column.ColumnName].ToString(); break; case "CustomField44": objContactMaster.CustomField44 = contact[column.ColumnName].ToString(); break; case "CustomField45": objContactMaster.CustomField45 = contact[column.ColumnName].ToString(); break; case "CustomField46": objContactMaster.CustomField46 = contact[column.ColumnName].ToString(); break; case "CustomField47": objContactMaster.CustomField47 = contact[column.ColumnName].ToString(); break; case "CustomField48": objContactMaster.CustomField48 = contact[column.ColumnName].ToString(); break; case "CustomField49": objContactMaster.CustomField49 = contact[column.ColumnName].ToString(); break; case "CustomField50": objContactMaster.CustomField50 = contact[column.ColumnName].ToString(); break; } } } #endregion objContactMaster.IsActive = true; objContactMaster.InsertWithDefaultValues(true); Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId); // ContactIds = ContactIds + ContactId + ","; QueryString = ""; for (int i = 0; i < contact.ItemArray.Length; i++) { QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!"; } if (!contatcInfo.ContainsKey(ContactId)) { contatcInfo.Add(ContactId, QueryString); validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";"; } else duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";"; } catch (Exception ex) { str.Append("<Error>Add New Contact: Problem at adding contact</Error>"); Logger.logdata(logforRpService, "Add New Contact: " + ex.Message); } } } unDeleverdInfo.Append("</UndeliveredList>"); } try { if (str.ToString().IndexOf("<Error>") == -1 && templateMaster != null && contatcInfo.Count > 0) { listMaster = new ListMasterBase(Con); listMaster.ListName = "TL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); listMaster.CreatedDate = System.DateTime.Now; listMaster.InsertWithDefaultValues(true); listid = Convert.ToInt64(listMaster.ListMasterID); //ContactIds = ContactIds.Substring(0, ContactIds.Length - 1); //string[] selectContact = ContactIds.Split(','); if (listid > 0) { DataTable dtListContactMaster = new DataTable(); dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool))); StringBuilder strbAddedContacts = new StringBuilder(); foreach (DictionaryEntry item in contatcInfo) { DataRow rowListContactMaster = dtListContactMaster.NewRow(); rowListContactMaster["ListMasterID"] = listid; rowListContactMaster["ContactId"] = item.Key; rowListContactMaster["CreatedDate"] = DateTime.Now.ToString(); rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString(); rowListContactMaster["IsActive"] = true; dtListContactMaster.Rows.Add(rowListContactMaster); } string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con); } } } catch (Exception ex) { str.Append("<Error>List: Problem at ListCreation contact</Error>"); Logger.logdata(logforRpService, "List: " + ex.Message); } #endregion ListMasterBase SuplistMaster = null; #region SuppressList contatcInfo = new Hashtable(); if (SuppressList.Tables.Count > 0 && SuppressList.Tables[0].Rows.Count > 0 && SuppressList.Tables[0].Columns.Contains("EmailAddress")) { contacts = SuppressList.Tables[0]; string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray(); string eidsString = String.Join(",", EmailIds); Logger.logdata(logforRpService, "EmailIds from User :"******"EmailAddress", contact["EmailAddress"].ToString(), Con); DataTable unSubDetails = new DataTable(); DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString()); if (contemail.Count > 0) { unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty); } if (unSubDetails.Rows.Count > 0) { //unDeleverdInfo.Append("<Undelivered>"); //unDeleverdInfo.Append("<ListType>Suppress</ListType>"); if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub") { //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); //unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>"); unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";"; } else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain") { //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); //unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>"); hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";"; } //unDeleverdInfo.Append("</Undelivered>"); } else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount) { //unDeleverdInfo.Append("<Undelivered>"); //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); //unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>"); //unDeleverdInfo.Append("</Undelivered>"); softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";"; } else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0) { try { if (contemail[0].IsActive == true) { QueryString = ""; for (int i = 0; i < contact.ItemArray.Length; i++) { QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!"; } if (!contatcInfo.ContainsKey(contemail[0].ContactId)) { contatcInfo.Add(contemail[0].ContactId, QueryString); validEmailIds = validEmailIds + contemail[0].EmailAddress + ";"; } else duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";"; ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString())); ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con); #region Handling Custom fields foreach (DataColumn column in contacts.Columns) { DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con); string custField = ""; if (customFieldDt.Rows.Count > 0) { custField = customFieldDt.Rows[0]["ContactFieldName"].ToString(); } else custField = column.ColumnName; if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString())) { switch (custField) { case "EmailAddress": objContactMaster.EmailAddress = contact[column.ColumnName].ToString(); break; case "FirstName": objContactMaster.FirstName = contact[column.ColumnName].ToString(); break; case "LastName": objContactMaster.LastName = contact[column.ColumnName].ToString(); break; case "Address1": objContactMaster.Address1 = contact[column.ColumnName].ToString(); break; case "City": objContactMaster.City = contact[column.ColumnName].ToString(); break; case "State": objContactMaster.State = contact[column.ColumnName].ToString(); break; case "PostalCode": objContactMaster.PostalCode = contact[column.ColumnName].ToString(); break; case "Country": objContactMaster.Country = contact[column.ColumnName].ToString(); break; case "WorkPhone": objContactMaster.WorkPhone = contact[column.ColumnName].ToString(); break; case "HomePhone": objContactMaster.HomePhone = contact[column.ColumnName].ToString(); break; case "MobilePhone": objContactMaster.MobilePhone = contact[column.ColumnName].ToString(); break; case "CustomField1": objContactMaster.CustomField1 = contact[column.ColumnName].ToString(); break; case "CustomField2": objContactMaster.CustomField2 = contact[column.ColumnName].ToString(); break; case "CustomField3": objContactMaster.CustomField3 = contact[column.ColumnName].ToString(); break; case "CustomField4": objContactMaster.CustomField4 = contact[column.ColumnName].ToString(); break; case "CustomField5": objContactMaster.CustomField5 = contact[column.ColumnName].ToString(); break; case "CustomField6": objContactMaster.CustomField6 = contact[column.ColumnName].ToString(); break; case "CustomField7": objContactMaster.CustomField7 = contact[column.ColumnName].ToString(); break; case "CustomField8": objContactMaster.CustomField8 = contact[column.ColumnName].ToString(); break; case "CustomField9": objContactMaster.CustomField9 = contact[column.ColumnName].ToString(); break; case "CustomField10": objContactMaster.CustomField10 = contact[column.ColumnName].ToString(); break; case "CustomField11": objContactMaster.CustomField11 = contact[column.ColumnName].ToString(); break; case "CustomField12": objContactMaster.CustomField12 = contact[column.ColumnName].ToString(); break; case "CustomField13": objContactMaster.CustomField13 = contact[column.ColumnName].ToString(); break; case "CustomField14": objContactMaster.CustomField14 = contact[column.ColumnName].ToString(); break; case "CustomField15": objContactMaster.CustomField15 = contact[column.ColumnName].ToString(); break; case "CustomField16": objContactMaster.CustomField16 = contact[column.ColumnName].ToString(); break; case "CustomField17": objContactMaster.CustomField17 = contact[column.ColumnName].ToString(); break; case "CustomField18": objContactMaster.CustomField18 = contact[column.ColumnName].ToString(); break; case "CustomField19": objContactMaster.CustomField19 = contact[column.ColumnName].ToString(); break; case "CustomField20": objContactMaster.CustomField20 = contact[column.ColumnName].ToString(); break; case "CustomField21": objContactMaster.CustomField21 = contact[column.ColumnName].ToString(); break; case "CustomField22": objContactMaster.CustomField22 = contact[column.ColumnName].ToString(); break; case "CustomField23": objContactMaster.CustomField23 = contact[column.ColumnName].ToString(); break; case "CustomField24": objContactMaster.CustomField24 = contact[column.ColumnName].ToString(); break; case "CustomField25": objContactMaster.CustomField25 = contact[column.ColumnName].ToString(); break; case "CustomField26": objContactMaster.CustomField26 = contact[column.ColumnName].ToString(); break; case "CustomField27": objContactMaster.CustomField27 = contact[column.ColumnName].ToString(); break; case "CustomField28": objContactMaster.CustomField28 = contact[column.ColumnName].ToString(); break; case "CustomField29": objContactMaster.CustomField29 = contact[column.ColumnName].ToString(); break; case "CustomField30": objContactMaster.CustomField30 = contact[column.ColumnName].ToString(); break; case "CustomField31": objContactMaster.CustomField31 = contact[column.ColumnName].ToString(); break; case "CustomField32": objContactMaster.CustomField32 = contact[column.ColumnName].ToString(); break; case "CustomField33": objContactMaster.CustomField33 = contact[column.ColumnName].ToString(); break; case "CustomField34": objContactMaster.CustomField34 = contact[column.ColumnName].ToString(); break; case "CustomField35": objContactMaster.CustomField35 = contact[column.ColumnName].ToString(); break; case "CustomField36": objContactMaster.CustomField36 = contact[column.ColumnName].ToString(); break; case "CustomField37": objContactMaster.CustomField37 = contact[column.ColumnName].ToString(); break; case "CustomField38": objContactMaster.CustomField38 = contact[column.ColumnName].ToString(); break; case "CustomField39": objContactMaster.CustomField39 = contact[column.ColumnName].ToString(); break; case "CustomField40": objContactMaster.CustomField40 = contact[column.ColumnName].ToString(); break; case "CustomField41": objContactMaster.CustomField41 = contact[column.ColumnName].ToString(); break; case "CustomField42": objContactMaster.CustomField42 = contact[column.ColumnName].ToString(); break; case "CustomField43": objContactMaster.CustomField43 = contact[column.ColumnName].ToString(); break; case "CustomField44": objContactMaster.CustomField44 = contact[column.ColumnName].ToString(); break; case "CustomField45": objContactMaster.CustomField45 = contact[column.ColumnName].ToString(); break; case "CustomField46": objContactMaster.CustomField46 = contact[column.ColumnName].ToString(); break; case "CustomField47": objContactMaster.CustomField47 = contact[column.ColumnName].ToString(); break; case "CustomField48": objContactMaster.CustomField48 = contact[column.ColumnName].ToString(); break; case "CustomField49": objContactMaster.CustomField49 = contact[column.ColumnName].ToString(); break; case "CustomField50": objContactMaster.CustomField50 = contact[column.ColumnName].ToString(); break; } } } #endregion if (objContactMaster.Update() == true) { //str.Append("<Message>Recipient Updated Successfully</Message>"); } else { //str.Append("<Error>Recipient Update Failed</Error>"); Logger.logdata(logforRpService, "Recipient Update Failed"); } } } catch (Exception ex) { str.Append("<Error>Edit Contact: Problem at updating contact</Error>"); Logger.logdata(logforRpService, "Update Contact :" + ex.Message); } } else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0) { try { ContactMaster objContactMaster = new ContactMaster(Con); objContactMaster.EmailAddress = contact["EmailAddress"].ToString(); objContactMaster.EmailContentType = "Html"; objContactMaster.CreatedDate = DateTime.Now; #region Handling Custom fields foreach (DataColumn column in contacts.Columns) { DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con); string custField = ""; if (customFieldDt.Rows.Count > 0) { custField = customFieldDt.Rows[0]["ContactFieldName"].ToString(); } else custField = column.ColumnName; if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString())) { switch (custField) { case "EmailAddress": objContactMaster.EmailAddress = contact[column.ColumnName].ToString(); break; case "FirstName": objContactMaster.FirstName = contact[column.ColumnName].ToString(); break; case "LastName": objContactMaster.LastName = contact[column.ColumnName].ToString(); break; case "Address1": objContactMaster.Address1 = contact[column.ColumnName].ToString(); break; case "City": objContactMaster.City = contact[column.ColumnName].ToString(); break; case "State": objContactMaster.State = contact[column.ColumnName].ToString(); break; case "PostalCode": objContactMaster.PostalCode = contact[column.ColumnName].ToString(); break; case "Country": objContactMaster.Country = contact[column.ColumnName].ToString(); break; case "WorkPhone": objContactMaster.WorkPhone = contact[column.ColumnName].ToString(); break; case "HomePhone": objContactMaster.HomePhone = contact[column.ColumnName].ToString(); break; case "MobilePhone": objContactMaster.MobilePhone = contact[column.ColumnName].ToString(); break; case "CustomField1": objContactMaster.CustomField1 = contact[column.ColumnName].ToString(); break; case "CustomField2": objContactMaster.CustomField2 = contact[column.ColumnName].ToString(); break; case "CustomField3": objContactMaster.CustomField3 = contact[column.ColumnName].ToString(); break; case "CustomField4": objContactMaster.CustomField4 = contact[column.ColumnName].ToString(); break; case "CustomField5": objContactMaster.CustomField5 = contact[column.ColumnName].ToString(); break; case "CustomField6": objContactMaster.CustomField6 = contact[column.ColumnName].ToString(); break; case "CustomField7": objContactMaster.CustomField7 = contact[column.ColumnName].ToString(); break; case "CustomField8": objContactMaster.CustomField8 = contact[column.ColumnName].ToString(); break; case "CustomField9": objContactMaster.CustomField9 = contact[column.ColumnName].ToString(); break; case "CustomField10": objContactMaster.CustomField10 = contact[column.ColumnName].ToString(); break; case "CustomField11": objContactMaster.CustomField11 = contact[column.ColumnName].ToString(); break; case "CustomField12": objContactMaster.CustomField12 = contact[column.ColumnName].ToString(); break; case "CustomField13": objContactMaster.CustomField13 = contact[column.ColumnName].ToString(); break; case "CustomField14": objContactMaster.CustomField14 = contact[column.ColumnName].ToString(); break; case "CustomField15": objContactMaster.CustomField15 = contact[column.ColumnName].ToString(); break; case "CustomField16": objContactMaster.CustomField16 = contact[column.ColumnName].ToString(); break; case "CustomField17": objContactMaster.CustomField17 = contact[column.ColumnName].ToString(); break; case "CustomField18": objContactMaster.CustomField18 = contact[column.ColumnName].ToString(); break; case "CustomField19": objContactMaster.CustomField19 = contact[column.ColumnName].ToString(); break; case "CustomField20": objContactMaster.CustomField20 = contact[column.ColumnName].ToString(); break; case "CustomField21": objContactMaster.CustomField21 = contact[column.ColumnName].ToString(); break; case "CustomField22": objContactMaster.CustomField22 = contact[column.ColumnName].ToString(); break; case "CustomField23": objContactMaster.CustomField23 = contact[column.ColumnName].ToString(); break; case "CustomField24": objContactMaster.CustomField24 = contact[column.ColumnName].ToString(); break; case "CustomField25": objContactMaster.CustomField25 = contact[column.ColumnName].ToString(); break; case "CustomField26": objContactMaster.CustomField26 = contact[column.ColumnName].ToString(); break; case "CustomField27": objContactMaster.CustomField27 = contact[column.ColumnName].ToString(); break; case "CustomField28": objContactMaster.CustomField28 = contact[column.ColumnName].ToString(); break; case "CustomField29": objContactMaster.CustomField29 = contact[column.ColumnName].ToString(); break; case "CustomField30": objContactMaster.CustomField30 = contact[column.ColumnName].ToString(); break; case "CustomField31": objContactMaster.CustomField31 = contact[column.ColumnName].ToString(); break; case "CustomField32": objContactMaster.CustomField32 = contact[column.ColumnName].ToString(); break; case "CustomField33": objContactMaster.CustomField33 = contact[column.ColumnName].ToString(); break; case "CustomField34": objContactMaster.CustomField34 = contact[column.ColumnName].ToString(); break; case "CustomField35": objContactMaster.CustomField35 = contact[column.ColumnName].ToString(); break; case "CustomField36": objContactMaster.CustomField36 = contact[column.ColumnName].ToString(); break; case "CustomField37": objContactMaster.CustomField37 = contact[column.ColumnName].ToString(); break; case "CustomField38": objContactMaster.CustomField38 = contact[column.ColumnName].ToString(); break; case "CustomField39": objContactMaster.CustomField39 = contact[column.ColumnName].ToString(); break; case "CustomField40": objContactMaster.CustomField40 = contact[column.ColumnName].ToString(); break; case "CustomField41": objContactMaster.CustomField41 = contact[column.ColumnName].ToString(); break; case "CustomField42": objContactMaster.CustomField42 = contact[column.ColumnName].ToString(); break; case "CustomField43": objContactMaster.CustomField43 = contact[column.ColumnName].ToString(); break; case "CustomField44": objContactMaster.CustomField44 = contact[column.ColumnName].ToString(); break; case "CustomField45": objContactMaster.CustomField45 = contact[column.ColumnName].ToString(); break; case "CustomField46": objContactMaster.CustomField46 = contact[column.ColumnName].ToString(); break; case "CustomField47": objContactMaster.CustomField47 = contact[column.ColumnName].ToString(); break; case "CustomField48": objContactMaster.CustomField48 = contact[column.ColumnName].ToString(); break; case "CustomField49": objContactMaster.CustomField49 = contact[column.ColumnName].ToString(); break; case "CustomField50": objContactMaster.CustomField50 = contact[column.ColumnName].ToString(); break; } } } #endregion objContactMaster.IsActive = true; objContactMaster.InsertWithDefaultValues(true); Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId); // ContactIds = ContactIds + ContactId + ","; QueryString = ""; for (int i = 0; i < contact.ItemArray.Length; i++) { QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!"; } if (!contatcInfo.ContainsKey(ContactId)) { contatcInfo.Add(ContactId, QueryString); validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";"; } else duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";"; } catch (Exception ex) { str.Append("<Error>Add New Contact: Problem at adding contact</Error>"); Logger.logdata(logforRpService, "Add New Contact: " + ex.Message); } } } } if (contatcInfo.Count > 0) { SuplistMaster = new ListMasterBase(Con); SuplistMaster.ListName = "SL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); SuplistMaster.CreatedDate = System.DateTime.Now; SuplistMaster.Active = false; SuplistMaster.InsertWithDefaultValues(true); SupListId = Convert.ToInt64(SuplistMaster.ListMasterID); ArrayList selectContact = new ArrayList(); ContactMasters contemail; foreach (DataRow recipient in SuppressList.Tables[0].Rows) { contemail = ContactMaster.SelectByField("EmailAddress", recipient["EmailAddress"].ToString(), Con); if (contemail.Count > 0) selectContact.Add(contemail[0].ContactId.ToString()); } if (SupListId > 0) { DataTable dtListContactMaster = new DataTable(); dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool))); StringBuilder strbAddedContacts = new StringBuilder(); foreach (DictionaryEntry item in contatcInfo) { DataRow rowListContactMaster = dtListContactMaster.NewRow(); rowListContactMaster["ListMasterID"] = SupListId; rowListContactMaster["ContactId"] = item.Key; rowListContactMaster["CreatedDate"] = DateTime.Now.ToString(); rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString(); rowListContactMaster["IsActive"] = true; dtListContactMaster.Rows.Add(rowListContactMaster); } string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con); } } #endregion ListMasterBase SeedlistMaster = null; #region SeedList contatcInfo = new Hashtable(); if (SeedList.Tables.Count > 0 && SeedList.Tables[0].Rows.Count > 0 && SeedList.Tables[0].Columns.Contains("EmailAddress")) { contacts = SeedList.Tables[0]; //DataRow dr; //if (ApproverMailID.Contains(',')) //{ // string[] MailIds = ApproverMailID.Split(','); // foreach (string mail in MailIds) // { // dr = contacts.NewRow(); // dr["EmailAddress"] = mail; // contacts.Rows.Add(dr); // } //} //else //{ // dr = contacts.NewRow(); // dr["EmailAddress"] = ApproverMailID; // contacts.Rows.Add(dr); //} string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray(); string eidsString = String.Join(",", EmailIds); Logger.logdata(logforRpService, "EmailIds from User :"******"EmailAddress", contact["EmailAddress"].ToString(), Con); DataTable unSubDetails = new DataTable(); DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString()); if (contemail.Count > 0) { unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty); } if (unSubDetails.Rows.Count > 0) { //unDeleverdInfo.Append("<Undelivered>"); // unDeleverdInfo.Append("<ListType>Seed</ListType>"); if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub") { // unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); //unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>"); unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";"; } else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain") { //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); //unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>"); hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";"; } //unDeleverdInfo.Append("</Undelivered>"); } else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount) { //unDeleverdInfo.Append("<Undelivered>"); //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>"); //unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>"); //unDeleverdInfo.Append("</Undelivered>"); softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";"; } else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0) { try { if (contemail[0].IsActive == true) { QueryString = ""; for (int i = 0; i < contact.ItemArray.Length; i++) { QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!"; } if (!contatcInfo.ContainsKey(contemail[0].ContactId)) { contatcInfo.Add(contemail[0].ContactId, QueryString); validEmailIds = validEmailIds + contemail[0].EmailAddress + ";"; } else duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";"; ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString())); ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con); #region Handling Custom fields foreach (DataColumn column in contacts.Columns) { DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con); string custField = ""; if (customFieldDt.Rows.Count > 0) { custField = customFieldDt.Rows[0]["ContactFieldName"].ToString(); } else custField = column.ColumnName; if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString())) { switch (custField) { case "EmailAddress": objContactMaster.EmailAddress = contact[column.ColumnName].ToString(); break; case "FirstName": objContactMaster.FirstName = contact[column.ColumnName].ToString(); break; case "LastName": objContactMaster.LastName = contact[column.ColumnName].ToString(); break; case "Address1": objContactMaster.Address1 = contact[column.ColumnName].ToString(); break; case "City": objContactMaster.City = contact[column.ColumnName].ToString(); break; case "State": objContactMaster.State = contact[column.ColumnName].ToString(); break; case "PostalCode": objContactMaster.PostalCode = contact[column.ColumnName].ToString(); break; case "Country": objContactMaster.Country = contact[column.ColumnName].ToString(); break; case "WorkPhone": objContactMaster.WorkPhone = contact[column.ColumnName].ToString(); break; case "HomePhone": objContactMaster.HomePhone = contact[column.ColumnName].ToString(); break; case "MobilePhone": objContactMaster.MobilePhone = contact[column.ColumnName].ToString(); break; case "CustomField1": objContactMaster.CustomField1 = contact[column.ColumnName].ToString(); break; case "CustomField2": objContactMaster.CustomField2 = contact[column.ColumnName].ToString(); break; case "CustomField3": objContactMaster.CustomField3 = contact[column.ColumnName].ToString(); break; case "CustomField4": objContactMaster.CustomField4 = contact[column.ColumnName].ToString(); break; case "CustomField5": objContactMaster.CustomField5 = contact[column.ColumnName].ToString(); break; case "CustomField6": objContactMaster.CustomField6 = contact[column.ColumnName].ToString(); break; case "CustomField7": objContactMaster.CustomField7 = contact[column.ColumnName].ToString(); break; case "CustomField8": objContactMaster.CustomField8 = contact[column.ColumnName].ToString(); break; case "CustomField9": objContactMaster.CustomField9 = contact[column.ColumnName].ToString(); break; case "CustomField10": objContactMaster.CustomField10 = contact[column.ColumnName].ToString(); break; case "CustomField11": objContactMaster.CustomField11 = contact[column.ColumnName].ToString(); break; case "CustomField12": objContactMaster.CustomField12 = contact[column.ColumnName].ToString(); break; case "CustomField13": objContactMaster.CustomField13 = contact[column.ColumnName].ToString(); break; case "CustomField14": objContactMaster.CustomField14 = contact[column.ColumnName].ToString(); break; case "CustomField15": objContactMaster.CustomField15 = contact[column.ColumnName].ToString(); break; case "CustomField16": objContactMaster.CustomField16 = contact[column.ColumnName].ToString(); break; case "CustomField17": objContactMaster.CustomField17 = contact[column.ColumnName].ToString(); break; case "CustomField18": objContactMaster.CustomField18 = contact[column.ColumnName].ToString(); break; case "CustomField19": objContactMaster.CustomField19 = contact[column.ColumnName].ToString(); break; case "CustomField20": objContactMaster.CustomField20 = contact[column.ColumnName].ToString(); break; case "CustomField21": objContactMaster.CustomField21 = contact[column.ColumnName].ToString(); break; case "CustomField22": objContactMaster.CustomField22 = contact[column.ColumnName].ToString(); break; case "CustomField23": objContactMaster.CustomField23 = contact[column.ColumnName].ToString(); break; case "CustomField24": objContactMaster.CustomField24 = contact[column.ColumnName].ToString(); break; case "CustomField25": objContactMaster.CustomField25 = contact[column.ColumnName].ToString(); break; case "CustomField26": objContactMaster.CustomField26 = contact[column.ColumnName].ToString(); break; case "CustomField27": objContactMaster.CustomField27 = contact[column.ColumnName].ToString(); break; case "CustomField28": objContactMaster.CustomField28 = contact[column.ColumnName].ToString(); break; case "CustomField29": objContactMaster.CustomField29 = contact[column.ColumnName].ToString(); break; case "CustomField30": objContactMaster.CustomField30 = contact[column.ColumnName].ToString(); break; case "CustomField31": objContactMaster.CustomField31 = contact[column.ColumnName].ToString(); break; case "CustomField32": objContactMaster.CustomField32 = contact[column.ColumnName].ToString(); break; case "CustomField33": objContactMaster.CustomField33 = contact[column.ColumnName].ToString(); break; case "CustomField34": objContactMaster.CustomField34 = contact[column.ColumnName].ToString(); break; case "CustomField35": objContactMaster.CustomField35 = contact[column.ColumnName].ToString(); break; case "CustomField36": objContactMaster.CustomField36 = contact[column.ColumnName].ToString(); break; case "CustomField37": objContactMaster.CustomField37 = contact[column.ColumnName].ToString(); break; case "CustomField38": objContactMaster.CustomField38 = contact[column.ColumnName].ToString(); break; case "CustomField39": objContactMaster.CustomField39 = contact[column.ColumnName].ToString(); break; case "CustomField40": objContactMaster.CustomField40 = contact[column.ColumnName].ToString(); break; case "CustomField41": objContactMaster.CustomField41 = contact[column.ColumnName].ToString(); break; case "CustomField42": objContactMaster.CustomField42 = contact[column.ColumnName].ToString(); break; case "CustomField43": objContactMaster.CustomField43 = contact[column.ColumnName].ToString(); break; case "CustomField44": objContactMaster.CustomField44 = contact[column.ColumnName].ToString(); break; case "CustomField45": objContactMaster.CustomField45 = contact[column.ColumnName].ToString(); break; case "CustomField46": objContactMaster.CustomField46 = contact[column.ColumnName].ToString(); break; case "CustomField47": objContactMaster.CustomField47 = contact[column.ColumnName].ToString(); break; case "CustomField48": objContactMaster.CustomField48 = contact[column.ColumnName].ToString(); break; case "CustomField49": objContactMaster.CustomField49 = contact[column.ColumnName].ToString(); break; case "CustomField50": objContactMaster.CustomField50 = contact[column.ColumnName].ToString(); break; } } } #endregion if (objContactMaster.Update() == true) { //str.Append("<Message>Recipient Updated Successfully</Message>"); } else { //str.Append("<Error>Recipient Update Failed</Error>"); Logger.logdata(logforRpService, "Recipient Update Failed"); } } } catch (Exception ex) { str.Append("<Error>Edit Contact: Problem at updating contact</Error>"); Logger.logdata(logforRpService, "Update Contact :" + ex.Message); } } else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0) { try { ContactMaster objContactMaster = new ContactMaster(Con); objContactMaster.EmailAddress = contact["EmailAddress"].ToString(); objContactMaster.EmailContentType = "Html"; objContactMaster.CreatedDate = DateTime.Now; #region Handling Custom fields foreach (DataColumn column in contacts.Columns) { DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con); string custField = ""; if (customFieldDt.Rows.Count > 0) { custField = customFieldDt.Rows[0]["ContactFieldName"].ToString(); } else custField = column.ColumnName; if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString())) { switch (custField) { case "EmailAddress": objContactMaster.EmailAddress = contact[column.ColumnName].ToString(); break; case "FirstName": objContactMaster.FirstName = contact[column.ColumnName].ToString(); break; case "LastName": objContactMaster.LastName = contact[column.ColumnName].ToString(); break; case "Address1": objContactMaster.Address1 = contact[column.ColumnName].ToString(); break; case "City": objContactMaster.City = contact[column.ColumnName].ToString(); break; case "State": objContactMaster.State = contact[column.ColumnName].ToString(); break; case "PostalCode": objContactMaster.PostalCode = contact[column.ColumnName].ToString(); break; case "Country": objContactMaster.Country = contact[column.ColumnName].ToString(); break; case "WorkPhone": objContactMaster.WorkPhone = contact[column.ColumnName].ToString(); break; case "HomePhone": objContactMaster.HomePhone = contact[column.ColumnName].ToString(); break; case "MobilePhone": objContactMaster.MobilePhone = contact[column.ColumnName].ToString(); break; case "CustomField1": objContactMaster.CustomField1 = contact[column.ColumnName].ToString(); break; case "CustomField2": objContactMaster.CustomField2 = contact[column.ColumnName].ToString(); break; case "CustomField3": objContactMaster.CustomField3 = contact[column.ColumnName].ToString(); break; case "CustomField4": objContactMaster.CustomField4 = contact[column.ColumnName].ToString(); break; case "CustomField5": objContactMaster.CustomField5 = contact[column.ColumnName].ToString(); break; case "CustomField6": objContactMaster.CustomField6 = contact[column.ColumnName].ToString(); break; case "CustomField7": objContactMaster.CustomField7 = contact[column.ColumnName].ToString(); break; case "CustomField8": objContactMaster.CustomField8 = contact[column.ColumnName].ToString(); break; case "CustomField9": objContactMaster.CustomField9 = contact[column.ColumnName].ToString(); break; case "CustomField10": objContactMaster.CustomField10 = contact[column.ColumnName].ToString(); break; case "CustomField11": objContactMaster.CustomField11 = contact[column.ColumnName].ToString(); break; case "CustomField12": objContactMaster.CustomField12 = contact[column.ColumnName].ToString(); break; case "CustomField13": objContactMaster.CustomField13 = contact[column.ColumnName].ToString(); break; case "CustomField14": objContactMaster.CustomField14 = contact[column.ColumnName].ToString(); break; case "CustomField15": objContactMaster.CustomField15 = contact[column.ColumnName].ToString(); break; case "CustomField16": objContactMaster.CustomField16 = contact[column.ColumnName].ToString(); break; case "CustomField17": objContactMaster.CustomField17 = contact[column.ColumnName].ToString(); break; case "CustomField18": objContactMaster.CustomField18 = contact[column.ColumnName].ToString(); break; case "CustomField19": objContactMaster.CustomField19 = contact[column.ColumnName].ToString(); break; case "CustomField20": objContactMaster.CustomField20 = contact[column.ColumnName].ToString(); break; case "CustomField21": objContactMaster.CustomField21 = contact[column.ColumnName].ToString(); break; case "CustomField22": objContactMaster.CustomField22 = contact[column.ColumnName].ToString(); break; case "CustomField23": objContactMaster.CustomField23 = contact[column.ColumnName].ToString(); break; case "CustomField24": objContactMaster.CustomField24 = contact[column.ColumnName].ToString(); break; case "CustomField25": objContactMaster.CustomField25 = contact[column.ColumnName].ToString(); break; case "CustomField26": objContactMaster.CustomField26 = contact[column.ColumnName].ToString(); break; case "CustomField27": objContactMaster.CustomField27 = contact[column.ColumnName].ToString(); break; case "CustomField28": objContactMaster.CustomField28 = contact[column.ColumnName].ToString(); break; case "CustomField29": objContactMaster.CustomField29 = contact[column.ColumnName].ToString(); break; case "CustomField30": objContactMaster.CustomField30 = contact[column.ColumnName].ToString(); break; case "CustomField31": objContactMaster.CustomField31 = contact[column.ColumnName].ToString(); break; case "CustomField32": objContactMaster.CustomField32 = contact[column.ColumnName].ToString(); break; case "CustomField33": objContactMaster.CustomField33 = contact[column.ColumnName].ToString(); break; case "CustomField34": objContactMaster.CustomField34 = contact[column.ColumnName].ToString(); break; case "CustomField35": objContactMaster.CustomField35 = contact[column.ColumnName].ToString(); break; case "CustomField36": objContactMaster.CustomField36 = contact[column.ColumnName].ToString(); break; case "CustomField37": objContactMaster.CustomField37 = contact[column.ColumnName].ToString(); break; case "CustomField38": objContactMaster.CustomField38 = contact[column.ColumnName].ToString(); break; case "CustomField39": objContactMaster.CustomField39 = contact[column.ColumnName].ToString(); break; case "CustomField40": objContactMaster.CustomField40 = contact[column.ColumnName].ToString(); break; case "CustomField41": objContactMaster.CustomField41 = contact[column.ColumnName].ToString(); break; case "CustomField42": objContactMaster.CustomField42 = contact[column.ColumnName].ToString(); break; case "CustomField43": objContactMaster.CustomField43 = contact[column.ColumnName].ToString(); break; case "CustomField44": objContactMaster.CustomField44 = contact[column.ColumnName].ToString(); break; case "CustomField45": objContactMaster.CustomField45 = contact[column.ColumnName].ToString(); break; case "CustomField46": objContactMaster.CustomField46 = contact[column.ColumnName].ToString(); break; case "CustomField47": objContactMaster.CustomField47 = contact[column.ColumnName].ToString(); break; case "CustomField48": objContactMaster.CustomField48 = contact[column.ColumnName].ToString(); break; case "CustomField49": objContactMaster.CustomField49 = contact[column.ColumnName].ToString(); break; case "CustomField50": objContactMaster.CustomField50 = contact[column.ColumnName].ToString(); break; } } } #endregion objContactMaster.IsActive = true; objContactMaster.InsertWithDefaultValues(true); Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId); // ContactIds = ContactIds + ContactId + ","; QueryString = ""; for (int i = 0; i < contact.ItemArray.Length; i++) { QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!"; } if (!contatcInfo.ContainsKey(ContactId)) { contatcInfo.Add(ContactId, QueryString); validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";"; } else duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";"; } catch (Exception ex) { str.Append("<Error>Add New Contact: Problem at adding contact</Error>"); Logger.logdata(logforRpService, "Add New Contact: " + ex.Message); } } } } if (contatcInfo.Count > 0) { SeedlistMaster = new ListMasterBase(Con); SeedlistMaster.ListName = "SDL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); SeedlistMaster.CreatedDate = System.DateTime.Now; SeedlistMaster.Active = true; SeedlistMaster.IsSeedList = true; SeedlistMaster.InsertWithDefaultValues(true); SeedListId = Convert.ToInt64(SeedlistMaster.ListMasterID); ArrayList selectContact = new ArrayList(); ContactMasters contemail; foreach (DataRow recipient in SeedList.Tables[0].Rows) { contemail = ContactMaster.SelectByField("EmailAddress", recipient["EmailAddress"].ToString(), Con); if (contemail.Count > 0) selectContact.Add(contemail[0].ContactId.ToString()); } if (SeedListId > 0) { DataTable dtListContactMaster = new DataTable(); dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool))); StringBuilder strbAddedContacts = new StringBuilder(); foreach (DictionaryEntry item in contatcInfo) { DataRow rowListContactMaster = dtListContactMaster.NewRow(); rowListContactMaster["ListMasterID"] = SeedListId; rowListContactMaster["ContactId"] = item.Key; rowListContactMaster["CreatedDate"] = DateTime.Now.ToString(); rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString(); rowListContactMaster["IsActive"] = true; dtListContactMaster.Rows.Add(rowListContactMaster); } string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con); } } #endregion CampaignMasters camp = CampaignMaster.SelectByField("CampaignName", CampaignName, Con); if (camp.Count > 0) { Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,Mailing with name " + CampaignName + " allready exist"); str.Append("<Error>Mailing : " + CampaignName + " allready exist</Error>"); } if (CampaignName.Length > 50) { Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,MailingName name max length exided"); str.Append("<Error>Mailing : Mailing name exided max length of 75 chars </Error>"); //mailContent.Append("<tr><td colspan=\"2\">Mailing : Mailing name exided max length of 75 chars</td></tr>"); } else if (templateMaster == null) { Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,TemplateName with name " + templateName + " not exist"); str.Append("<Error>Tempalte : " + templateName + " not found</Error>"); //mailContent.Append("<tr><td colspan=\"2\">Tempalte : " + templateName + " not found</td></tr>"); } else if (listid <= 0) { Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,List with id " + listid.ToString() + " not exist"); str.Append("<Error>List :Zero records found(Check contact status)</Error>"); //mailContent.Append("<tr><td colspan=\"2\">List :Zero records found(Check contact status)</td></tr>"); } #region Schedule Camapign string CampainID = "False"; str.Append("<MailingDetails>"); if (str.ToString().IndexOf("<Error>") == -1) { CampainID = ScheduleMailingWithSuppressList(Con, CampaignName, Subject, FromName, ReplyToAddress, FromAddress, templateName, listid.ToString(), SupListId.ToString(), SeedListId.ToString(), SchedulteDate, sendType); if (CampainID != "False") { string message = string.Empty; SendTestMail(TemplateContent, CampainID, Convert.ToInt64(SeedListId), ApproverMailID, FromAddress, FromName, ReplyToAddress, Subject, Con); mailingId = CampainID; str.Append("<MailingID>" + CampainID + "</MailingID>"); str.Append("<TemplateName>" + templateName + "</TemplateName>"); str.Append("<TemplateID>" + templateMaster.TemplateId + "</TemplateID>"); str.Append("<ListName>" + listMaster.ListName + "</ListName>"); str.Append("<ListID>" + listMaster.ListMasterID + "</ListID>"); Logger.logdata(logforRpService, "Success ::Mailing ID: " + CampainID + " ;Mailing Name : " + CampaignName + ";List Name: " + listMaster.ListName); Logger.logdata(logforRpService, "No. of valid Contacts found : " + contatcInfo.Count); Logger.logdata(logforRpService, "No. of invalid Contacts found: " + (contacts.Rows.Count - contatcInfo.Count)); Logger.logdata(logforRpService, "valid Contacts found : " + validEmailIds); Logger.logdata(logforRpService, "Unsubscribed Mails :" + unsubEmailIds); Logger.logdata(logforRpService, "HardBounce triggered Mails :" + hardBounceEmailIds); Logger.logdata(logforRpService, "SoftBounce triggered Mails :" + softBounceEmailIds); Logger.logdata(logforRpService, "Duplicate EmailIds :" + duplicateEmailids); string ApproverPagePath = ConfigurationManager.AppSettings["ApproverPagePath"]; if (ApproverPagePath.Trim().Length > 0) ApproverPagePath = ApproverPagePath + "?UserName="******"&MailingID=" + CampainID; mailContent.Append("<tr><td colspan=\"2\" height=\"70\" align=\"left\" valign=\"middle\" style=\"padding-bottom:10px; font-family:arial; font-size:13px; color:#666; font-weight:bold;\">Dear Member,<br/><br/>Your request for Email campaign scheduling has been received to our system successfully via API Call.<br/> Have a look at the Email campaign data submitted to the system and click on Approve Email button provided at end of this email to approve this job.</td></tr>"); mailContent.Append("<tr><td align=\"center\" valign=\"top\" style=\"-webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; border:solid #016ab3; border-width:1px;-webkit-box-shadow: 2px 2px 4px #999; -moz-box-shadow: 2px 2px 4px #999; box-shadow: 2px 2px 4px #999;\">"); mailContent.Append("<table width=\"500\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" >"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Client/User</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + UserID + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Mailing Name</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + CampaignName + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Mailing ID</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + mailingId + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">From Name </td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + FromName + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">From Mail</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + FromAddress + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Subject</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + Subject + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Reply To Mail</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + ReplyToAddress + "</td></tr>"); if (Recipients.Tables.Count > 0) mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Mailing List File Quantity </td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + Recipients.Tables[0].Rows.Count + "</td></tr>"); if (SuppressList.Tables.Count > 0) mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Suppress List File Quantity </td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + SuppressList.Tables[0].Rows.Count + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Schedule Date/Time</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + SchedulteDate + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Mailing List Name</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + listMaster.ListName + "</td></tr>"); mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#0288cd; font-weight:bold;\">Mailing List ID</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">" + listMaster.ListMasterID + "</td></tr>"); mailContent.Append("</table></td></tr>"); mailContent.Append("</table>"); mailContent.Append("<table width=\"700\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">"); mailContent.Append("<tr><td></td><td align=\"center\" valign=\"middle\" style=\"height: 50px\"><a href=\"" + ApproverPagePath + "\" onclick=\"window.open(this.href, 'ApproveMailing','left=20,top=20,width=550,height=200,toolbar=1,resizable=0'); return false;\"><img src=\"http://mta1.1pointinteractive.com/1Point/images/btn-approve-email.png\" /></a></td></tr>"); mailContent.Append("<tr><td colspan=\"2\" align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">Thanks,</td></tr>"); mailContent.Append("<tr><td colspan=\"2\" align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#666; font-weight:bold;\">1Point Support Team</td></tr>"); mailContent.Append("</table>"); if (toReportMailID.Trim().Length > 0) { string fromMail = ConfigurationManager.AppSettings["ApiFromMail"]; bool status = true; if (!ApproverMailID.Contains(',')) status = sendEMail(fromMail, ApproverMailID, ReplyToAddress, "API Log Report_" + CampaignName, false, mailContent.ToString(), out message); else { status = sendEMail(fromMail, ApproverMailID, ReplyToAddress, "API Log Report_" + CampaignName, false, mailContent.ToString(), out message); } MailApproval objMailApproval = new MailApproval(Con); objMailApproval.MailingID = Convert.ToInt64(CampainID); objMailApproval.ApprovalMail = ApproverMailID; objMailApproval.ReportMailTo = toReportMailID; objMailApproval.ApprovalStatus = "NotApproved"; objMailApproval.IsApprovalSent = status; objMailApproval.IsReportMailied = false; objMailApproval.IsActive = false; objMailApproval.OneHr = false; objMailApproval.TwoHr = false; objMailApproval.FourHr = false; objMailApproval.EightHr = false; objMailApproval.Insert(); } } else { str.Append("<Error>ScheduleMailing : Problem at scheduling a mailing</Error>"); Logger.logdata(logforRpService, "Problem at scheduling Mailing"); } } if (str.ToString().IndexOf("<Error>") == -1) str.Append("<Status>True</Status>"); else str.Append("<Status>False</Status>"); str.Append("</MailingDetails>"); LogEndInfo("LaunchMailingWithSuppressList"); #endregion } else { Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Column with name EmailAddress(and/or)FirstName(and/or)LastName not found in input DataSet"); str.Append("<Error>Input DataSet:Contact must contain EmailAddress Field</Error>"); } } else { str.Append("<Error>Invalid UserID OR Password</Error>"); str.Append("<MailingDetails>"); str.Append("<Status>False</Status>"); str.Append("</MailingDetails>"); Logger.logdata(logforRpService, "Invalid UserID OR Password"); } } catch (Exception ex) { str.Append("<Error>Failed to connect database</Error>"); str.Append("<MailingDetails>"); str.Append("<Status>False</Status>"); str.Append("</MailingDetails>"); Logger.logError(logforRpService, ex); } str.Append("</MailingList>"); if (str.ToString().IndexOf("<Error>") == -1) str.Append("<SubMailingCount>" + subMailVertion + "</SubMailingCount>"); str.Append(unDeleverdInfo); str.Append("</MailingInfo>"); doc.LoadXml(str.ToString()); return doc; }
public void updateIsReportStatus(int MailingId) { #region Update 'IsReportMailied' status in MailApproval Table MailApproval objMailApproval = new MailApproval(clientConnectionString); objMailApproval.MailingID = MailingId; objMailApproval.IsReportMailied = true; bool updateStatus = objMailApproval.UpdateIsReportMailiedStatus(); if (updateStatus) Logger.logdata(logforemailbuilder, string.Format("IsReportMailiedStatus Updated Successfully {0}", DateTime.Now.ToString())); else Logger.logdata(logforemailbuilder, string.Format("IsReportMailiedStatus Updated Failed {0}", DateTime.Now.ToString())); #endregion }
public void getMailingRpt(DataRow dr, int RptSenthr) { Logger.logdata(logforemailbuilder, "************** in getMailingRpt(..) method **************"); Logger.logdata(logforemailbuilder, string.Format("getMailingRpt(..) has been started at {0}", DateTime.Now.ToString())); string message = string.Empty; int MailingId = Convert.ToInt32(dr["MailingID"].ToString()); Logger.logdata(logforemailbuilder, string.Format("Mailing Id:{0}", MailingId.ToString())); //string[] rptMailIds= dr["ReportMailTo"].ToString().Split(','); string rptMailTo = dr["ReportMailTo"].ToString(); CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(MailingId); CampaignMaster objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, clientConnectionString); CampaignJobPrimaryKey pk = new CampaignJobPrimaryKey(MailingId); CampaignJobs objCampaignjob = CampaignJob.SelectByField("CampaignMasterID", MailingId, clientConnectionString); string MailinName = objCampaignMaster.CampaignName.ToString(); Logger.logdata(logforemailbuilder, string.Format("MailingName:{0}", MailinName.ToString())); string Subject = objCampaignMaster.Subject.ToString(); string sentTime = objCampaignjob[0].ScheduledDatetime.ToString(); string completionTime = objCampaignjob[0].CompletionTime.ToString(); string DeliveredCount = objCampaignjob[0].DeliveredCount.ToString(); string BounceCount = objCampaignjob[0].BounceCount.ToString(); string OpenCount = objCampaignjob[0].OpenCount.ToString(); string ClickCount = objCampaignjob[0].ClickCount.ToString(); string UnsubscribeCount = objCampaignjob[0].UnSubscribeCount.ToString(); ListMasterPrimaryKey pkList = new ListMasterPrimaryKey(Convert.ToInt32(objCampaignMaster.SelectCondition)); ListMaster listMaster = ListMaster.SelectOne(pkList, connectionString); string listName = listMaster.ListName; ListContactMaster objListContactMaster = new ListContactMaster(clientConnectionString); DataTable dtcontacts = objListContactMaster.getContactsWithCampaignID(objCampaignMaster.SelectCondition, MailingId.ToString()); string TargetedCount = dtcontacts.Rows.Count.ToString(); int ForwardCount = -1; int Fcount = LinkDetailBase.RecipientsForwardCount(clientConnectionString, MailingId, out ForwardCount); string forwardCount = Fcount.ToString(); #region MailBody StringBuilder mailContent = new StringBuilder(); mailContent.Append("<table width=\"600px\">"); mailContent.Append("<tr><td style=\"font-weight: bold\">Mailing Report Summary</td></tr>"); mailContent.Append("<tr><td width=\"250px\">Mailing Name:</td><td>" + MailinName + "</td></tr>"); mailContent.Append("<tr><td>Subject Line:</td><td>" + Subject + "</td></tr>"); mailContent.Append("<tr><td>Send Start Date:</td><td>" + sentTime + "</td></tr>"); mailContent.Append("<tr><td>Send Completion Date :</td><td>" + completionTime + "</td></tr>"); mailContent.Append("<tr><td>List Name:</td><td>" + listName + "</td></tr>"); mailContent.Append("<tr><td style=\"height:20px\"></td><td></td></tr>"); mailContent.Append("<tr><td style=\"font-weight:bold\">Overall Stats</td></tr>"); mailContent.Append("<tr><td>Contacts Targeted</td><td>" + TargetedCount + "</td></tr>"); mailContent.Append("<tr><td>Successful Delivered</td> <td>" + DeliveredCount + "</td></tr>"); mailContent.Append("<tr><td>BounceCount</td> <td>" + BounceCount + "</td></tr>"); mailContent.Append("<tr><td>OpenCount</td> <td>" + OpenCount + "</td></tr>"); mailContent.Append("<tr><td>ClickCount</td> <td>" + ClickCount + "</td></tr>"); mailContent.Append("<tr><td>UnsubscribeCount</td><td>" + UnsubscribeCount + "</td></tr>"); mailContent.Append("<tr><td>ForwardCount</td><td>" + forwardCount + "</td></tr>"); mailContent.Append("</table>"); Logger.logdata(logforemailbuilder, string.Format("MailingBody :{0}", mailContent.ToString())); #endregion try { #region Build Mail Body DataTable DataTable mailRptDt = new DataTable(); DataColumn s1 = new DataColumn("Mailing Report Summary"); DataColumn s2 = new DataColumn(" "); mailRptDt.Columns.Add(s1); mailRptDt.Columns.Add(s2); DataRow row1 = mailRptDt.NewRow(); row1[s1] = "Mailing Name:"; row1[s2] = MailinName; mailRptDt.Rows.Add(row1); DataRow row2 = mailRptDt.NewRow(); row2[s1] = "Subject Line:"; row2[s2] = Subject; mailRptDt.Rows.Add(row2); DataRow row3 = mailRptDt.NewRow(); row3[s1] = "Send Start Date:"; row3[s2] = sentTime; mailRptDt.Rows.Add(row3); DataRow row4 = mailRptDt.NewRow(); row4[s1] = "Send Completion Date :"; row4[s2] = completionTime; mailRptDt.Rows.Add(row4); DataRow row5 = mailRptDt.NewRow(); row5[s1] = "List Name:"; row5[s2] = listName; mailRptDt.Rows.Add(row5); DataRow row6 = mailRptDt.NewRow(); row6[s1] = ""; row6[s2] = ""; mailRptDt.Rows.Add(row6); DataRow row7 = mailRptDt.NewRow(); row7[s1] = "Overall Stats"; row7[s2] = ""; mailRptDt.Rows.Add(row7); DataRow row8 = mailRptDt.NewRow(); row8[s1] = "Contacts Targeted:"; row8[s2] = TargetedCount; mailRptDt.Rows.Add(row8); DataRow row9 = mailRptDt.NewRow(); row9[s1] = "Successful Delivered:"; row9[s2] = DeliveredCount; mailRptDt.Rows.Add(row9); DataRow row10 = mailRptDt.NewRow(); row10[s1] = "Bounce Count:"; row10[s2] = BounceCount; mailRptDt.Rows.Add(row10); DataRow row11 = mailRptDt.NewRow(); row11[s1] = "Open Count:"; row11[s2] = OpenCount; mailRptDt.Rows.Add(row11); DataRow row12 = mailRptDt.NewRow(); row12[s1] = "Click Count:"; row12[s2] = ClickCount; mailRptDt.Rows.Add(row12); DataRow row13 = mailRptDt.NewRow(); row13[s1] = "Unsubscribe Count:"; row13[s2] = UnsubscribeCount; mailRptDt.Rows.Add(row13); DataRow row14 = mailRptDt.NewRow(); row14[s1] = "Forward Count:"; row14[s2] = forwardCount; mailRptDt.Rows.Add(row14); #endregion string dat = DateTime.Now.ToString("ddMMMyyyyhhmmssTT"); string pPath = ConfigurationSettings.AppSettings["AttachFilePath"].ToString(); string apiFromMail = ConfigurationSettings.AppSettings["ApiFromMail"].ToString(); DirectoryInfo dirInfo = new DirectoryInfo(pPath); if (!dirInfo.Exists) dirInfo.Create(); pPath = Path.Combine(pPath, "MailingReport" + dat + ".csv"); Logger.logdata(logforemailbuilder, string.Format("Attachment Path: {0}", pPath.ToString())); CreateCSVFile(mailRptDt, pPath); Logger.logdata(logforemailbuilder, string.Format("sendEmail(..) has been started at {0}", DateTime.Now.ToString())); bool status = sendEmail(apiFromMail, rptMailTo.ToString().Trim(), string.Empty, "Report", false, mailContent.ToString(), pPath, out message); if (status) { Logger.logdata(logforemailbuilder, "Report Mail Sent Successfully to:'" + rptMailTo + "'"); #region Update Hours status in MailApproval Table MailApproval objMailApproval = new MailApproval(clientConnectionString); bool updateStatus = objMailApproval.UpdateHoursStatus(MailingId, RptSenthr); if (updateStatus) Logger.logdata(logforemailbuilder, string.Format("{0} Hours Status Updated Successfully at {1}", RptSenthr.ToString(), DateTime.Now.ToString())); else Logger.logdata(logforemailbuilder, string.Format("{0} Hours Status Updated Failed at {1}", RptSenthr.ToString(), DateTime.Now.ToString())); #endregion } else { Logger.logdata(logforemailbuilder, "Report Mail Sending Failed"); } Logger.logdata(logforemailbuilder, string.Format("sendEmail(..) method has been ended at {0}", DateTime.Now.ToString())); } catch (Exception ex) { } Logger.logdata(logforemailbuilder, string.Format("getMailingRpt(..) method has been ended at {0}", DateTime.Now.ToString())); Logger.logdata(logforemailbuilder, "************** Exit getMailingRpt(..) method **************"); }