Example #1
0
        private void Send(bool optionCustomersWithOrders, bool optionNewsletterSubscribers)
        {
            string       mailSubject = txtSubject.Text;
            string       mailBody    = radDescription.Content;
            string       mailFooter  = new Topic("mailfooter").Contents;
            List <EMail> mailingList = new List <EMail>();

            if (optionNewsletterSubscribers)
            {
                mailingList = EMail.MailingList(BulkMailTypeEnum.NewsLetter, optionCustomersWithOrders, mailSubject);
            }
            else
            {
                mailingList = EMail.MailingList(BulkMailTypeEnum.EmailBlast, optionCustomersWithOrders, mailSubject);
            }

            BulkMailing bm = new BulkMailing(mailingList, mailBody, mailSubject, mailFooter, true, Session.SessionID);

            if (bm.MailingList.Count > 0)
            {
                BulkMailing.ExecuteAsyncBulkSend executeAsyncSend = new BulkMailing.ExecuteAsyncBulkSend(bm.ExecuteBulkSend);

                //We will check status in case the operation finishes and we need to re-enable buttons, etc.
                AsyncCallback cb = new AsyncCallback(MailingComplete);

                executeAsyncSend.BeginInvoke(cb, null);

                ifrStatus.Attributes["src"] = "asyncstatus.aspx?id=" + Session.SessionID;
                ifrStatus.Visible           = true;

                ltError.Text = AppLogic.GetString("admin.mailingmgr.BulkMailSending", ThisCustomer.LocaleSetting);

                btnRemoveEmail.Enabled = false;
                btnSend.Enabled        = false;
            }
            else
            {
                btnRemoveEmail.Enabled = true;
                btnSend.Enabled        = true;

                ifrStatus.Visible = false;

                ltError.Text = AppLogic.GetString("admin.mailingmgr.NoEmails", ThisCustomer.LocaleSetting);
            }
        }
Example #2
0
 public void MailingComplete(IAsyncResult ar)
 {
     BulkMailing.ExecuteAsyncBulkSend executeAsyncSend = (BulkMailing.ExecuteAsyncBulkSend)((AsyncResult)ar).AsyncDelegate;
     executeAsyncSend.EndInvoke(ar);
 }
Example #3
0
        /// <summary>
        /// Handles the send button OnClick event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSend_Click(object sender, EventArgs e)
        {
            bool   testOnly       = (rbTestOnly.SelectedValue == "1");
            bool   withOrdersOnly = (rbCustomersWithOrder.SelectedValue == "1");
            bool   listOnly       = (rbListCustomers.SelectedValue == "1");
            bool   newsLetter     = (rbNewsletter.SelectedValue == "1");
            string mailSubject    = txtSubject.Text;
            string mailBody       = radDescription.Content;
            string mailFooter     = new Topic("mailfooter").Contents;

            StringBuilder emailListText = new StringBuilder();
            List <EMail>  mailingList   = new List <EMail>();

            if (newsLetter)
            {
                mailingList = EMail.NewsLetterMailingList();
            }
            else
            {
                mailingList = EMail.MailingList(BulkMailTypeEnum.EmailBlast, withOrdersOnly, mailSubject);
            }

            if (listOnly)
            {
                List <GridCustomer> l = GridCustomer.GetCustomers();

                //List<GridProductVariant> l = GridProductVariant.GetAllVariants(false, AppLogic.EntityType.Unknown, 0);

                List <object> newList = l.ConvertAll <object>(delegate(GridCustomer g) { return((object)g); });

                Response.Clear();
                Response.ClearHeaders();
                Response.ClearContent();
                Response.AddHeader("content-disposition", "attachment; filename=MailingList.csv");
                Response.ContentType = "text/csv";
                Response.AddHeader("Pragma", "public");
                Response.Write(CSVExporter.ExportListToCSV(newList));
                Response.End();
            }
            else
            {
                //Send a single message to the currently logged in user
                if (testOnly)
                {
                    EMail objEmail = new EMail();

                    objEmail.RecipientID   = ThisCustomer.CustomerID;
                    objEmail.RecipientGuid = ThisCustomer.CustomerGUID;
                    objEmail.EmailAddress  = ThisCustomer.EMail;
                    objEmail.MailSubject   = mailSubject;
                    objEmail.MailContents  = mailBody;
                    objEmail.MailFooter    = (new Topic("mailfooter").Contents);
                    objEmail.IncludeFooter = true;
                    objEmail.LogMessage    = true;

                    objEmail.Send();
                }
                //Sending Emails
                else
                {
                    BulkMailing bm = new BulkMailing(mailingList, mailBody, mailSubject, mailFooter, true, Session.SessionID);

                    if (bm.MailingList.Count > 0)
                    {
                        BulkMailing.ExecuteAsyncBulkSend executeAsyncSend = new BulkMailing.ExecuteAsyncBulkSend(bm.ExecuteBulkSend);

                        //We will check status in case the operation finishes and we need to re-enable buttons, etc.
                        AsyncCallback cb = new AsyncCallback(MailingComplete);

                        IAsyncResult result = executeAsyncSend.BeginInvoke(cb, null);

                        ifrStatus.Attributes["src"] = "asyncstatus.aspx?id=" + Session.SessionID;
                        ifrStatus.Visible           = true;

                        ltError.Text = AppLogic.GetString("admin.mailingmgr.BulkMailSending", ThisCustomer.LocaleSetting);

                        btnRemoveEmail.Enabled = false;
                        btnSend.Enabled        = false;
                    }
                    else
                    {
                        btnRemoveEmail.Enabled = true;
                        btnSend.Enabled        = true;

                        ifrStatus.Visible = false;

                        ltError.Text = AppLogic.GetString("admin.mailingmgr.NoEmails", ThisCustomer.LocaleSetting);
                    }
                }
            }
        }