//[Read("smtp/test")]
        //public SmtpOperationStatus TestSmtpSettings()
        //{
        //    CheckSmtpPermissions();

        //    var settings = ToSmtpSettings(CoreConfiguration.SmtpSettings);

        //    //add resolve
        //    var smtpTestOp = new SmtpOperation(settings, Tenant.TenantId, SecurityContext.CurrentAccount.ID, UserManager, SecurityContext, TenantManager, Configuration);

        //    SMTPTasks.QueueTask(smtpTestOp.RunJob, smtpTestOp.GetDistributedTask());

        //    return ToSmtpOperationStatus();
        //}

        //[Read("smtp/test/status")]
        //public SmtpOperationStatus GetSmtpOperationStatus()
        //{
        //    CheckSmtpPermissions();

        //    return ToSmtpOperationStatus();
        //}

        //private SmtpOperationStatus ToSmtpOperationStatus()
        //{
        //    var operations = SMTPTasks.GetTasks().ToList();

        //    foreach (var o in operations)
        //    {
        //        if (!string.IsNullOrEmpty(o.InstanseId) &&
        //            Process.GetProcesses().Any(p => p.Id == int.Parse(o.InstanseId)))
        //            continue;

        //        o.SetProperty(SmtpOperation.PROGRESS, 100);
        //        SMTPTasks.RemoveTask(o.Id);
        //    }

        //    var operation =
        //        operations
        //            .FirstOrDefault(t => t.GetProperty<int>(SmtpOperation.OWNER) == Tenant.TenantId);

        //    if (operation == null)
        //    {
        //        return null;
        //    }

        //    if (DistributedTaskStatus.Running < operation.Status)
        //    {
        //        operation.SetProperty(SmtpOperation.PROGRESS, 100);
        //        SMTPTasks.RemoveTask(operation.Id);
        //    }

        //    var result = new SmtpOperationStatus
        //    {
        //        Id = operation.Id,
        //        Completed = operation.GetProperty<bool>(SmtpOperation.FINISHED),
        //        Percents = operation.GetProperty<int>(SmtpOperation.PROGRESS),
        //        Status = operation.GetProperty<string>(SmtpOperation.RESULT),
        //        Error = operation.GetProperty<string>(SmtpOperation.ERROR),
        //        Source = operation.GetProperty<string>(SmtpOperation.SOURCE)
        //    };

        //    return result;
        //}

        public static SmtpSettings ToSmtpSettingsConfig(SmtpSettingsWrapper settingsWrapper)
        {
            var settingsConfig = new SmtpSettings(
                settingsWrapper.Host,
                settingsWrapper.Port ?? SmtpSettings.DefaultSmtpPort,
                settingsWrapper.SenderAddress,
                settingsWrapper.SenderDisplayName)
            {
                EnableSSL  = settingsWrapper.EnableSSL,
                EnableAuth = settingsWrapper.EnableAuth
            };

            if (settingsWrapper.EnableAuth)
            {
                settingsConfig.SetCredentials(settingsWrapper.CredentialsUserName, settingsWrapper.CredentialsUserPassword);
            }

            return(settingsConfig);
        }
Beispiel #2
0
        public SmtpSettingsWrapper SaveSmtpSettings(SmtpSettingsWrapper smtpSettings)
        {
            CheckSmtpPermissions();

            //TODO: Add validation check

            if (smtpSettings == null)
            {
                throw new ArgumentNullException("smtpSettings");
            }

            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var settingConfig = ToSmtpSettingsConfig(smtpSettings);

            CoreContext.Configuration.SmtpSettings = settingConfig;

            var settings = ToSmtpSettings(settingConfig, true);

            return(settings);
        }
 public SmtpSettingsWrapper SaveSmtpSettingsFromForm([FromForm] SmtpSettingsWrapper smtpSettings)
 {
     return(SaveSmtpSettings(smtpSettings));
 }
 public SmtpSettingsWrapper SaveSmtpSettingsFromBody([FromBody] SmtpSettingsWrapper smtpSettings)
 {
     return(SaveSmtpSettings(smtpSettings));
 }