/// <summary> /// Instantiates a new intance of the EMail Class /// </summary> public EMail() { //Set default values from AppConfigs m_MailServer = AppLogic.AppConfig("MailMe_Server"); m_FromAddress = AppLogic.AppConfig("MailMe_FromAddress"); m_FromName = AppLogic.AppConfig("MailMe_FromeName"); m_StoreURL = AppLogic.GetStoreHTTPLocation(false); m_UseHTML = true; m_IncludeFooter = true; m_LogMessage = false; m_MailType = BulkMailTypeEnum.None; m_MailFooter = String.Empty; }
public static List <NewsLetter> NewsLetterMailingList(bool withOrdersOnly) { BulkMailTypeEnum listType = BulkMailTypeEnum.NewsLetter; string mailingSubject = String.Empty; List <NewsLetter> mailObjectList = new List <NewsLetter>(); SqlParameter spListType = new SqlParameter("@ListType", (int)listType); SqlParameter spWithOrdersOnly = new SqlParameter("@withOrdersOnly", (withOrdersOnly ? 1 : 0)); SqlParameter spMailingSubject = new SqlParameter("@mailingSubject", mailingSubject); SqlParameter[] spa = { spListType, spWithOrdersOnly, spMailingSubject }; using (SqlConnection conn = new SqlConnection(DB.GetDBConn())) { conn.Open(); using (IDataReader rs = DB.ExecuteStoredProcReader("[dbo].[aspdnsf_getMailingList]", spa, conn)) { while (rs.Read()) { var email = DB.RSField(rs, "EmailAddress"); Customer customer = new Customer(email); if (!withOrdersOnly || (customer != null && customer.HasOrders())) { NewsLetter objMailing = new NewsLetter(); objMailing.RecipientID = DB.RSFieldInt(rs, "RecipientID"); objMailing.EmailAddress = email; objMailing.StoreId = DB.RSFieldInt(rs, "StoreId"); objMailing.FirstName = DB.RSField(rs, "FirstName"); objMailing.LastName = DB.RSField(rs, "LastName"); objMailing.SubscribedOn = DB.RSFieldDateTime(rs, "SubscribedOn"); mailObjectList.Add(objMailing); } } rs.Close(); rs.Dispose(); } conn.Close(); conn.Dispose(); } return(mailObjectList); }
/// <summary> /// Generic List of EMail objects that can be utilized to send mailings. /// !!!WARNING!!! Do NOT set the contents property on the entire list! This method can /// generate TENS OR HUNDREDS OF THOUSANDS of objects, consuming GIGABYTES OF MEMORY! /// Contents should be set individually in the routine that loops through the list to /// send the emails. /// </summary> /// <param name="listType"> /// Determines whether the list is built off of the Customers or Newsletter table. /// EmailBlast = Customers, Newsletter = NewsLetter /// </param> /// <param name="withOrdersOnly"> /// If BulkMailTypeEnum = EmailBlast, determines if only Customers with orders are returned /// </param> /// <param name="mailingSubject"> /// The subject of the mailing that the list is being generated for. /// Used to check for duplicate mailings to the same customer /// </param> /// <returns> /// Generic List containing all mailing objects that meet the qualification parameters. /// </returns> public static List <EMail> MailingList(BulkMailTypeEnum listType, bool withOrdersOnly, string mailingSubject) { List <EMail> mailObjectList = new List <EMail>(); SqlParameter spListType = new SqlParameter("@ListType", (int)listType); SqlParameter spWithOrdersOnly = new SqlParameter("@withOrdersOnly", (withOrdersOnly ? 1 : 0)); SqlParameter spMailingSubject = new SqlParameter("@mailingSubject", mailingSubject); SqlParameter[] spa = { spListType, spWithOrdersOnly, spMailingSubject }; using (SqlConnection conn = new SqlConnection(DB.GetDBConn())) { conn.Open(); using (IDataReader rs = DB.ExecuteStoredProcReader("[dbo].[aspdnsf_getMailingList]", spa, conn)) { while (rs.Read()) { EMail objMailing = new EMail(); objMailing.RecipientID = DB.RSFieldInt(rs, "RecipientID"); objMailing.RecipientGuid = DB.RSFieldGUID(rs, "RecipientGuid"); objMailing.EmailAddress = DB.RSField(rs, "EmailAddress"); objMailing.FirstName = DB.RSField(rs, "FirstName"); objMailing.LastName = DB.RSField(rs, "LastName"); mailObjectList.Add(objMailing); } rs.Close(); rs.Dispose(); } conn.Close(); conn.Dispose(); } return(mailObjectList); }