Exemplo n.º 1
0
        /// <summary>
        /// Sends the newsletter.
        /// </summary>
        /// <returns></returns>
        private string SendNewsletter(Job job)
        {
            JobWorkItems workItemsForProcessing = job.GetWorkItems();

            if (workItemsForProcessing.Items.Count == 0)
            {
                DebugWrite("Work Items collection is empty. Nothing to send.");
                return("Work Items collection is empty. Nothing to send.");
            }

            // Get information about what we're about to send
            EPiMailEngine   mailEngine = new EPiMailEngine();
            MailSenderBase  msbase     = mailEngine.GetMailSender();
            MailInformation mailInfo   = msbase.GetMailMetaData(new PageReference(job.PageId));

            // const int sleepTestInterval = 0;
            DebugWrite(string.Format("Start sending newsletter. Job name: '{0}', Subject: '{1}', From: '{2}'",
                                     job.Name, mailInfo.Subject, mailInfo.From));

            // Send the message

            // For testing, it can be nice to control the time it takes to send
            // each batch
//#if DEBUG
//            if (sleepTestInterval > 0)
//                System.Threading.Thread.Sleep(sleepTestInterval);
//#endif
            // Send with status

            SendMailLog log;

            log = mailEngine.SendNewsletter(mailInfo.Subject,
                                            mailInfo.From,          /* Who we send from */
                                            mailInfo.PageLink,      /* The page to send */
                                            workItemsForProcessing, /* Who we send to */
                                            false /* Not Test Mode */);
//#if DEBUG
//            if (sleepTestInterval > 0)
//                System.Threading.Thread.Sleep(sleepTestInterval);
//#endif
            return(log.GetClearTextLogString(true /* Use br instead of \n */));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the mail.
        /// </summary>
        /// <param name="engine">The engine.</param>
        /// <param name="workItems">The work items.</param>
        public void SendMail(EPiMailEngine engine, JobWorkItems workItems, bool isTestSend)
        {
            if (_log.IsDebugEnabled())
            {
                _log.Debug("Starting send process. Testmode: " + isTestSend.ToString());
            }

            // First we verify the environment
            if (VerifyEnvironment(engine) == false)
            {
                return;
            }

            // Collection of recipients from job
            if (workItems == null)
            {
                throw new NullReferenceException("workItems cannot be null when sending newsletter");
            }

            if (workItems.Items.Count == 0)
            {
                ShowError("No recipients defined. Please add email addresses to textbox above Test Send button.");
                return;
            }

            // Need default values
            // 1. Use MailSender property
            // 2. Use EPsSendMailFromAddress from web.config
            // 3. Construct newsletter@<sitename>
            string fromAddress = MailFrom;

            // 1. Use MailSubject property
            // 2. Use EPsSendMailSubject from web.config
            // 3. Use "Newsletter" as default
            string subject = MailSubject;

            if (isTestSend)
            {
                subject += TEST_SUBJECT_POSTFIX;
            }

            if (_log.IsDebugEnabled())
            {
                _log.Debug(string.Format("Start sending newsletter based on WorkItems. Subject: '{0}', From: '{1}', Count '{2}', Test Mode: '{3}'",
                                         subject, fromAddress, workItems.Items.Count.ToString(), isTestSend.ToString()));
            }

            // Send the message
            string sendStatus;
            // We set testsend as false in the method below, as the test sending UI has changed, but the
            // logic in the engine interpret this as not sending anything. Test here means change the
            // email subject
            SendMailLog log = engine.SendNewsletter(subject, fromAddress, CurrentPage.ContentLink, workItems, false);

            sendStatus = log.GetClearTextLogString(true);

            lblSendResult.Text    = sendStatus;
            pnlSendResult.Visible = true;

            if (_log.IsDebugEnabled())
            {
                _log.Debug("Send process finished. Testmode: " + isTestSend.ToString());
            }
        }