ServerFactoryNewServer Method |
Namespace: AskiaPortalCmn
public static IServer NewServer( IContext context, string type, ConnectionStringType connectionStringType, Nullable<Guid> moduleGuid = null )
Create a new server 'SMTP' server for the `AskiaPortal` module and save it.
var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D")); var contextValidation = context.Validate(); if (!contextValidation.Success) { throw contextValidation.Exception; } Guid askiaPortalGuid = Guid.Parse("5F856C7A-2F60-47C5-A90C-23BC2F179CBC"); var server = ServerFactory.NewServer(context, "smtp", ConnectionStringType.Smtp, askiaPortalGuid); if (server == null) { Console.Error.WriteLine("Could not create a server."); return; } server.Name = "MySecondSMTPServer"; server.Description = "Second SMTP server"; var smtpConnectionString = new SmtpConnectionString { Host = "server.domain.ext", Port = 25, UseSsl = true, UserName = "myusername", Password = "secret" }; server.ConnectionString = smtpConnectionString.ToString(); var saveResult = server.Save(); if (saveResult.Success) { Console.WriteLine("The server (Id={0}) was successfully saved", server.Id); } else { Console.Error.Write(saveResult.Exception.Message); }