Exemple #1
0
        public ActionResult TestSettings(TestSmtpSettings testSettings)
        {
            ILogger logger = null;

            try {
                var fakeLogger           = new FakeLogger();
                var smtpChannelComponent = _smtpChannel as Component;
                if (smtpChannelComponent != null)
                {
                    logger = smtpChannelComponent.Logger;
                    smtpChannelComponent.Logger = fakeLogger;
                }

                // Temporarily update settings so that the test will actually use the specified host, port, etc.
                var smtpSettings = _orchardServices.WorkContext.CurrentSite.As <SmtpSettingsPart>();

                smtpSettings.Address               = testSettings.From;
                smtpSettings.Host                  = testSettings.Host;
                smtpSettings.Port                  = testSettings.Port;
                smtpSettings.EnableSsl             = testSettings.EnableSsl;
                smtpSettings.RequireCredentials    = testSettings.RequireCredentials;
                smtpSettings.UseDefaultCredentials = testSettings.UseDefaultCredentials;
                smtpSettings.UserName              = testSettings.UserName;
                smtpSettings.Password              = testSettings.Password;

                if (!smtpSettings.IsValid())
                {
                    fakeLogger.Error("Invalid settings.");
                }
                else
                {
                    _smtpChannel.Process(new Dictionary <string, object> {
                        { "Recipients", testSettings.To },
                        { "Subject", T("Orchard CMS - SMTP settings test email").Text }
                    });
                }

                if (!String.IsNullOrEmpty(fakeLogger.Message))
                {
                    return(Json(new { error = fakeLogger.Message }));
                }

                return(Json(new { status = T("Message sent.").Text }));
            }
            catch (Exception e) {
                return(Json(new { error = e.Message }));
            }
            finally {
                var smtpChannelComponent = _smtpChannel as Component;
                if (smtpChannelComponent != null)
                {
                    smtpChannelComponent.Logger = logger;
                }

                // Undo the temporarily changed smtp settings.
                _orchardServices.TransactionManager.Cancel();
            }
        }
        public ActionResult TestSettings(TestSmtpSettings testSettings)
        {
            ILogger logger = null;
            try {
                var fakeLogger = new FakeLogger();
                var smtpChannelComponent = _smtpChannel as Component;
                if (smtpChannelComponent != null) {
                    logger = smtpChannelComponent.Logger;
                    smtpChannelComponent.Logger = fakeLogger;
                }

                // Temporarily update settings so that the test will actually use the specified host, port, etc.
                var smtpSettings = _orchardServices.WorkContext.CurrentSite.As<SmtpSettingsPart>();

                smtpSettings.Address = testSettings.From;
                smtpSettings.Host = testSettings.Host;
                smtpSettings.Port = testSettings.Port;
                smtpSettings.EnableSsl = testSettings.EnableSsl;
                smtpSettings.RequireCredentials = testSettings.RequireCredentials;
                smtpSettings.UseDefaultCredentials = testSettings.UseDefaultCredentials;
                smtpSettings.UserName = testSettings.UserName;
                smtpSettings.Password = testSettings.Password;

                if (!smtpSettings.IsValid()) {
                    fakeLogger.Error("Invalid settings.");
                }
                else {
                    _smtpChannel.Process(new Dictionary<string, object> {
                        {"Recipients", testSettings.To},
                        {"Subject", testSettings.Subject},
                        {"Body", testSettings.Body},
                        {"ReplyTo", testSettings.ReplyTo},
                        {"Bcc", testSettings.Bcc},
                        {"CC", testSettings.Cc}
                    });
                }

                if (!String.IsNullOrEmpty(fakeLogger.Message)) {
                    return Json(new { error = fakeLogger.Message });
                }

                return Json(new {status = T("Message sent.").Text});
            }
            catch (Exception e) {
                return Json(new {error = e.Message});
            }
            finally {
                var smtpChannelComponent = _smtpChannel as Component;
                if (smtpChannelComponent != null) {
                    smtpChannelComponent.Logger = logger;
                }

                // Undo the temporarily changed smtp settings.
                _orchardServices.TransactionManager.Cancel();
            }
        }
Exemple #3
0
        public ActionResult TestSettings(TestSmsSettings testSettings)
        {
            ILogger logger = null;

            try {
                var fakeLogger          = new FakeLogger();
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null)
                {
                    logger = smsChannelComponent.Logger;
                    smsChannelComponent.Logger = fakeLogger;
                }

                // Temporarily update settings so that the test will actually use the specified host, port, etc.
                var smsSettings = _orchardServices.WorkContext.CurrentSite.As <SmsSettingsPart>();

                smsSettings.AccountSid   = testSettings.AccountSid;
                smsSettings.AuthToken    = testSettings.AuthToken;
                smsSettings.TwilioNumber = testSettings.From;

                if (!smsSettings.IsValid())
                {
                    fakeLogger.Error("Invalid settings.");
                }
                else
                {
                    _smsChannel.Process(new Dictionary <string, object> {
                        { "Recipients", testSettings.To },
                        { "Body", testSettings.Body }
                    });
                }

                if (!String.IsNullOrEmpty(fakeLogger.Message))
                {
                    return(Json(new { error = fakeLogger.Message }));
                }

                return(Json(new { status = T("Message sent.").Text }));
            }
            catch (Exception e) {
                return(Json(new { error = e.Message }));
            }
            finally {
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null)
                {
                    smsChannelComponent.Logger = logger;
                }

                // Undo the temporarily changed smtp settings.
                _orchardServices.TransactionManager.Cancel();
            }
        }
        public ActionResult TestSettings(TestSmsSettings testSettings)
        {
            ILogger logger = null;
            try {
                var fakeLogger = new FakeLogger();
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null) {
                    logger = smsChannelComponent.Logger;
                    smsChannelComponent.Logger = fakeLogger;
                }

                // Temporarily update settings so that the test will actually use the specified host, port, etc.
                var smsSettings = _orchardServices.WorkContext.CurrentSite.As<SmsSettingsPart>();

                smsSettings.AccountSid = testSettings.AccountSid;
                smsSettings.AuthToken = testSettings.AuthToken;
                smsSettings.TwilioNumber = testSettings.From;

                if (!smsSettings.IsValid()) {
                    fakeLogger.Error("Invalid settings.");
                }
                else {
                    _smsChannel.Process(new Dictionary<string, object> {
                        {"Recipients", testSettings.To},
                        {"Body", testSettings.Body}
                    });
                }

                if (!String.IsNullOrEmpty(fakeLogger.Message)) {
                    return Json(new { error = fakeLogger.Message });
                }

                return Json(new {status = T("Message sent.").Text});
            }
            catch (Exception e) {
                return Json(new {error = e.Message});
            }
            finally {
                var smsChannelComponent = _smsChannel as Component;
                if (smsChannelComponent != null) {
                    smsChannelComponent.Logger = logger;
                }

                // Undo the temporarily changed smtp settings.
                _orchardServices.TransactionManager.Cancel();
            }
        }