Ejemplo n.º 1
0
        public void UpdateServer(ApiModel.Server serverUpdate)
        {
            ServerOptions newSettings      = serverOptions.CurrentValue;
            RelayOptions  newRelaySettings = relayOptions.CurrentValue;

            newSettings.Port     = serverUpdate.PortNumber;
            newSettings.HostName = serverUpdate.HostName;
            newSettings.AllowRemoteConnections = serverUpdate.AllowRemoteConnections;
            newSettings.NumberOfMessagesToKeep = serverUpdate.NumberOfMessagesToKeep;
            newSettings.NumberOfSessionsToKeep = serverUpdate.NumberOfSessionsToKeep;

            newRelaySettings.SmtpServer      = serverUpdate.RelayOptions.SmtpServer;
            newRelaySettings.SmtpPort        = serverUpdate.RelayOptions.SmtpPort;
            newRelaySettings.SenderAddress   = serverUpdate.RelayOptions.SenderAddress;
            newRelaySettings.Login           = serverUpdate.RelayOptions.Login;
            newRelaySettings.Password        = serverUpdate.RelayOptions.Password;
            newRelaySettings.AutomaticEmails = serverUpdate.RelayOptions.AutomaticEmails;

            if (!serverUpdate.IsRunning && this.server.IsRunning)
            {
                this.server.Stop();
            }
            else if (serverUpdate.IsRunning && !this.server.IsRunning)
            {
                this.server.TryStart();
            }

            string dataDir      = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "smtp4dev");
            string settingsFile = Path.Join(dataDir, "appsettings.json");

            System.IO.File.WriteAllText(settingsFile, JsonSerializer.Serialize(new { ServerOptions = newSettings, RelayOptions = newRelaySettings }, new JsonSerializerOptions {
                WriteIndented = true
            }));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateServer(ApiModel.Server serverUpdate)
        {
            if (!hostingEnvironmentHelper.SettingsAreEditable)
            {
                return(Forbid());
            }
            ServerOptions newSettings      = serverOptions.CurrentValue;
            RelayOptions  newRelaySettings = relayOptions.CurrentValue;

            newSettings.Port     = serverUpdate.PortNumber;
            newSettings.HostName = serverUpdate.HostName;
            newSettings.AllowRemoteConnections = serverUpdate.AllowRemoteConnections;
            newSettings.NumberOfMessagesToKeep = serverUpdate.NumberOfMessagesToKeep;
            newSettings.NumberOfSessionsToKeep = serverUpdate.NumberOfSessionsToKeep;
            newSettings.ImapPort = serverUpdate.ImapPortNumber;

            newRelaySettings.SmtpServer      = serverUpdate.RelayOptions.SmtpServer;
            newRelaySettings.SmtpPort        = serverUpdate.RelayOptions.SmtpPort;
            newRelaySettings.TlsMode         = Enum.Parse <SecureSocketOptions>(serverUpdate.RelayOptions.TlsMode);
            newRelaySettings.SenderAddress   = serverUpdate.RelayOptions.SenderAddress;
            newRelaySettings.Login           = serverUpdate.RelayOptions.Login;
            newRelaySettings.Password        = serverUpdate.RelayOptions.Password;
            newRelaySettings.AutomaticEmails = serverUpdate.RelayOptions.AutomaticEmails;

            System.IO.File.WriteAllText(hostingEnvironmentHelper.GetEditableSettingsFilePath(),
                                        JsonSerializer.Serialize(new { ServerOptions = newSettings, RelayOptions = newRelaySettings },
                                                                 new JsonSerializerOptions {
                WriteIndented = true
            }));

            if (!serverUpdate.IsRunning && this.server.IsRunning)
            {
                this.server.Stop();
            }
            else if (serverUpdate.IsRunning && !this.server.IsRunning)
            {
                this.server.TryStart();
            }

            if (!serverUpdate.IsRunning && this.imapServer.IsRunning)
            {
                this.imapServer.Stop();
            }
            else if (serverUpdate.IsRunning && !this.imapServer.IsRunning)
            {
                this.imapServer.TryStart();
            }


            return(Ok());
        }