Example #1
0
        public void EmailAsHtmlWithRTLSetFormatsCorrectly()
        {
            var inputContext = new Mock<IInputContext>();
            var siteList = new Mock<ISiteList>();
            IDnaDiagnostics diagnostics;

            siteList.Setup(x => x.GetSiteOptionValueBool(0,"General","RTLSite")).Returns(true);

            inputContext.Setup(x => x.TheSiteList).Returns(siteList.Object);
            DnaMessage message = new DnaMessage(inputContext.Object);

            var subject = "This is the subject";
            var body = "This is the body\n\rwith two lines";
            var sender = "*****@*****.**";
            var recipient = sender;
            message.SendEmail(subject, body, sender, recipient,0);
        }
Example #2
0
        public void SendEmailViaDatabaseWithValidData_CorrectDataInEmailQueue()
        {
            string toAddress = "*****@*****.**";
            string fromAddress = "*****@*****.**";
            string ccAddress = "*****@*****.**";
            string body = "Testing that we put emails correctly in the database";
            string subject = "Database queued email";
            int siteId = 1;

            IInputContext context = _mocks.DynamicMock<IInputContext>();
            IDnaDiagnostics diagnostics = _mocks.DynamicMock<IDnaDiagnostics>();
            ISiteList siteList = _mocks.DynamicMock<ISiteList>();
            IDnaDataReaderCreator dataReaderCreator = _mocks.DynamicMock<IDnaDataReaderCreator>();

            context.Stub(x => x.Diagnostics).Return(diagnostics);
            context.Stub(x => x.TheSiteList).Return(siteList);
            context.Stub(x => x.CreateDnaDataReaderCreator()).Return(dataReaderCreator);

            diagnostics.Stub(x => x.WriteExceptionToLog(null));

            siteList.Stub(x => x.GetSiteOptionValueBool(siteId, "General", "UseSystemMessages")).Return(false);
            siteList.Stub(x => x.GetSiteOptionValueBool(siteId, "General", "RTLSite")).Return(false);

            using (IDnaDataReader firstReader = StoredProcedureReader.Create("QueueEmail", ConnectionDetails))
            {
                dataReaderCreator.Stub(x => x.CreateDnaDataReader("QueueEmail")).Return(firstReader);

                _mocks.ReplayAll();

                DnaMessage message = new DnaMessage(context);
                message.SendEmailOrSystemMessage(0, toAddress, fromAddress, ccAddress, siteId, subject, body);
            }

            using (IDnaDataReader reader = StoredProcedureReader.Create("", ConnectionDetails))
            {
                reader.ExecuteDEBUGONLY(@"EXEC getemailbatchtosend 2");
                if (reader.Read() && reader.HasRows)
                {
                    Assert.AreEqual(toAddress, reader.GetString("ToEmailAddress"));
                    Assert.AreEqual(fromAddress, reader.GetString("FromEmailAddress"));
                    Assert.AreEqual(ccAddress, reader.GetString("CCAddress"));
                    Assert.AreEqual(body, reader.GetString("body"));
                    Assert.AreEqual(subject, reader.GetString("subject"));
                }
                reader.Close();
            }
        }
        /// <summary>
        /// Send the email to the configured recipients once a term is added/updated
        /// </summary>
        /// <param name="terms"></param>
        /// <param name="forumId"></param>
        /// <param name="termReason"></param>
        /// <param name="termAction"></param>
        /// <param name="userId"></param>
        private void SendTermUpdateEmail(string[] terms, int forumId, string termReason, TermAction termAction, int userId)
        {
            #region local var(s) declaration

            var _forumTitle = string.Empty;
            var _forumURL = string.Empty;
            var _siteId = InputContext.CurrentSite.SiteID;
            var _emailSubject = string.Empty;
            var _emailBody = string.Empty;
            
            #region Terms Details

            var _emailCustomBody = string.Empty;
            var _termAction = string.Empty;

            var _strTerms = String.Join(",", terms.ToArray());

            _emailCustomBody += "\r\n" + "Terms    : " + _strTerms + "\r\n";
            _emailCustomBody += "Reason   : " + termReason + "\r\n";
            
            switch(termAction)
            {
                case TermAction.Refer:
                    _termAction = "Send to moderation";
                    break;
                case TermAction.ReEdit:
                    _termAction = "Ask to re-edit"; 
                    break;
                case TermAction.NoAction:
                    _termAction = "Terms deleted";
                    break;
            }

            _emailCustomBody += "Action   : " + _termAction + "\r\n";
            _emailCustomBody += "Author   : " + InputContext.ViewingUser.UserName + "\r\n";
            _emailCustomBody += "DateTime : " + System.DateTime.Now.ToString();

            #endregion

            var _sender = InputContext.ViewingUser.Email;

            var _recipient = System.Configuration.ConfigurationManager.AppSettings["ModerateEmailGroup"].ToString();
            _recipient += ";" + InputContext.CurrentSite.EditorsEmail;
            _recipient += ";" + InputContext.ViewingUser.Email;

            var _termsFilterLink = "https://ssl.bbc.co.uk/dna/moderation/admin/termsfilterimport";

            #endregion

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("getcommentforumdetailsbyforumid"))
            {
                dataReader.AddParameter("@forumid", forumId);
                dataReader.Execute();
                if (true == dataReader.HasRows && true == dataReader.Read())
                {
                    _forumTitle = dataReader.GetStringNullAsEmpty("TITLE");
                    _forumURL = dataReader.GetStringNullAsEmpty("URL");
                }
            }
           
            EmailTemplates.FetchEmailText(InputContext.CreateDnaDataReaderCreator(), _siteId, "TermsAddedToCommentForumEmail", out _emailSubject, out _emailBody);
    
            _emailBody = _emailBody.Replace("++**forum_title**++", _forumTitle);
            _emailBody = _emailBody.Replace("++**forum_url**++", _forumURL);
            _emailBody = _emailBody.Replace("++**term_details**++", _emailCustomBody);
            _emailBody = _emailBody.Replace("++**terms_filter**++", _termsFilterLink);
            _emailBody = _emailBody.Replace("++**new_line**++", "\r\n");
            _emailSubject = _emailSubject.Replace("++**forum_title**++", _forumTitle);


            try
            {
                //Actually send the email.
                DnaMessage sendMessage = new DnaMessage(InputContext);
                sendMessage.SendEmailOrSystemMessage(userId, _recipient, _sender, _siteId, _emailSubject, _emailBody);
            }
            catch (DnaEmailException e)
            {
                AddErrorXml("EMAIL", "Unable to send email." + e.Message, RootElement);
            }
           
        }
Example #4
0
        /// <summary>
        /// Sends Email to the given recipient. eg If a nickname is failed the user concerned will be sent a 
        /// notification email.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="siteId"></param>
        /// <param name="oldNickName"></param>
        /// <param name="userEmail"></param>
        /// <exception cref="DnaException">If there is an error sending email.</exception>
        private void SendEmail(int userId, int siteId, string oldNickName, string userEmail )
        {

            // do any necessary substitutions
            string emailSubject;
            string emailBody;
            EmailTemplates.FetchEmailText(AppContext.ReaderCreator, siteId, "NicknameResetEmail", out emailSubject, out emailBody);
            emailSubject = emailSubject.Replace("++**nickname**++", oldNickName);
            emailBody = emailBody.Replace("++**nickname**++", oldNickName);
            emailSubject = emailSubject.Replace("++**userid**++", userId.ToString());
            emailBody = emailBody.Replace("++**userid**++", userId.ToString());

            string moderatorEmail = InputContext.TheSiteList.GetSite(siteId).GetEmail(BBC.Dna.Sites.Site.EmailType.Moderators);

            try
            {
                //Actually send the email.
                DnaMessage sendMessage = new DnaMessage(InputContext);
                sendMessage.SendEmailOrSystemMessage(userId, userEmail, moderatorEmail, siteId, emailSubject, emailBody);
            }
            catch (DnaEmailException e)
            {
                //Uable to usefully handle the error here so rethrow.
                string error = "Unable to send Email. Sender:" + e.Sender + " Recipient: " + e.Recipient + "." + e.Message;
                throw new DnaException(error);
            }
        }