コード例 #1
0
        public async Task <IActionResult> SmtpTestAsync()
        {
            // Read POST body to SmtpMailTest object
            SmtpConfiguration smtpTest;

            using (var reader = new StreamReader(Request.Body))
            {
                string body = await reader.ReadToEndAsync();

                if (string.IsNullOrWhiteSpace(body))
                {
                    return(BadRequest());
                }
                _logger.LogDebug("Form body for SMTP test: {0}", body);
                smtpTest = await SmtpConfiguration.ParseJsonAsync(body);
            }

            // Validate data
            if (smtpTest == null || !smtpTest.ValidateTest())
            {
                return(Ok(new FailureResponse("SMTP test data not valid")));
            }

            try
            {
                // Perform test
                if (!_mailService.SendTestMail(smtpTest))
                {
                    return(Ok(new FailureResponse("SMTP test failed")));
                }

                // Return success
                return(Ok(new SuccessResponse()));
            }
            catch (SmtpException exSmtp)
            {
                // Failed with exception
                return(Ok(new ErrorRespose(exSmtp)));
            }
            catch (AuthenticationException exAuth)
            {
                // Failed with exception
                return(Ok(new ErrorRespose(exAuth)));
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses a JSON string and applies the configuration values to the model
        /// </summary>
        /// <param name="jsonData">JSON string</param>
        public override async Task ApplyJsonPropertiesAsync(string jsonData)
        {
            SmtpConfiguration configuration = await SmtpConfiguration.ParseJsonAsync(jsonData);

            CopyPropertyValues(this, configuration);
        }