private void RemoveDomain(int tenant, string user, int domainId) { try { var serverDal = new ServerDal(tenant); var serverData = serverDal.GetTenantServer(); if ((ServerType)serverData.type != ServerType.Postfix) { return; } var mailserverfactory = new PostfixFactory(); var setup = new ServerSetup .Builder(serverData.id, tenant, user) .SetConnectionString(serverData.connection_string) .SetLogger(_log) .Build(); var mailServer = mailserverfactory.CreateServer(setup); var domain = mailServer.GetWebDomain(domainId, mailserverfactory); mailServer.DeleteWebDomain(domain, mailserverfactory); } catch (Exception ex) { _log.Error("RemoveDomain(tenant={0}, user=\"{1}\", domainId={2}) Exception: \r\n {3} \r\n", tenant, user, domainId, ex.ToString()); } }
public void TestCreatedServerWithJsonConnectionString() { const string server_connection_string = "{\"DbConnection\" : \"Server=54.228.253.62;Database=vmail;User ID=vmailadmin;Password=ESbWgt5Xym1SRjGfHL0rsi4VVZbldk;Pooling=True;Character Set=utf8\", " + "\"Api\":{\"Protocol\":\"http\", \"Server\":\"54.228.253.62\", \"Port\":\"8081\", \"Version\":\"v1\",\"Token\":\"6ffcb0f58a3d950ee49104177f7f1d96\"}}"; const int server_id = 3; const int tenant_id = 1; const string user_id = "some_user_id"; var limits = new ServerLimits.Builder() .SetMailboxMaxCountPerUser(2) .Build(); var setup = new ServerSetup .Builder(server_id, tenant_id, user_id) .SetConnectionString(server_connection_string) .SetServerLimits(limits) .Build(); var serverBase = factory.CreateServer(setup); Assert.AreEqual(serverBase.Tenant, tenant_id); Assert.AreEqual(serverBase.User, user_id); Assert.AreEqual(serverBase.Id, server_id); Assert.AreEqual(serverBase.ConnectionString, server_connection_string); Assert.AreEqual(serverBase.Logger.GetType(), typeof(NullLogger)); Assert.AreEqual(serverBase.SetupInfo.Limits, limits); }
public virtual void TestCreatedServer() { var limits = new ServerLimits.Builder() .SetMailboxMaxCountPerUser(2) .Build(); var setup = new ServerSetup .Builder(1, 3, "some_user_id") .SetConnectionString("server_connection") .SetServerLimits(limits) .Build(); var serverBase = factory.CreateServer(setup); Assert.AreEqual(1, serverBase.Id); Assert.AreEqual(3, serverBase.Tenant); Assert.AreEqual("some_user_id", serverBase.User); Assert.AreEqual(serverBase.Logger.GetType(), typeof(NullLogger)); Assert.AreEqual(serverBase.SetupInfo.Limits, limits); }
public MailServerBase CreateServer() { var serverConnectionString = HttpUtility.UrlDecode(ConfigurationManager.AppSettings["ConnectionString"]); var tenantId = int.Parse(ConfigurationManager.AppSettings["TenantId"]); var userId = ConfigurationManager.AppSettings["TeamlabUserGuid"].ToString(CultureInfo.InvariantCulture); var serverId = int.Parse(ConfigurationManager.AppSettings["ServerId"]); var logger = LoggerFactory.GetLogger(LoggerFactory.LoggerType.Null, string.Empty); CoreContext.TenantManager.SetCurrentTenant(tenantId); var limits = new ServerLimits.Builder() .SetMailboxMaxCountPerUser(10) .Build(); var setup = new ServerSetup .Builder(serverId, tenantId, userId) .SetConnectionString(serverConnectionString) .SetLogger(logger) .SetServerLimits(limits) .Build(); return(ServerFactory.CreateServer(setup)); }
private void RemoveDomain(int tenant, string user, int domainId) { var serverDal = new ServerDal(tenant); var serverData = serverDal.GetTenantServer(); if ((ServerType)serverData.type != ServerType.Postfix) { return; } var mailserverfactory = new PostfixFactory(); var setup = new ServerSetup .Builder(serverData.id, tenant, user) .SetConnectionString(serverData.connection_string) .SetLogger(_log) .Build(); var mailServer = mailserverfactory.CreateServer(setup); var domain = mailServer.GetWebDomain(domainId, mailserverfactory); mailServer.DeleteWebDomain(domain, mailserverfactory); }
private void RemoveTeamlabMailbox(MailBox mailbox) { if (mailbox == null) { throw new ArgumentNullException("mailbox"); } if (!mailbox.IsTeamlab) { return; } try { var serverDal = new ServerDal(mailbox.TenantId); var serverData = serverDal.GetTenantServer(); if ((ServerType)serverData.type != ServerType.Postfix) { throw new NotSupportedException(); } var mailserverfactory = new PostfixFactory(); var limits = new ServerLimits.Builder() .SetMailboxMaxCountPerUser(2) .Build(); var dnsPresets = new DnsPresets.Builder() .SetMx(serverData.mx_record, 0) .SetSpfValue("Spf") .SetDkimSelector("Dkim") .SetDomainCheckPrefix("DomainCheck") .Build(); var setup = new ServerSetup .Builder(serverData.id, mailbox.TenantId, mailbox.UserId) .SetConnectionString(serverData.connection_string) .SetLogger(_log) .SetServerLimits(limits) .SetDnsPresets(dnsPresets) .Build(); var mailServer = mailserverfactory.CreateServer(setup); var tlMailbox = mailServer.GetMailbox(mailbox.MailBoxId, mailserverfactory); if (tlMailbox == null) { return; } var groups = mailServer.GetMailGroups(mailserverfactory); var groupsContainsMailbox = groups.Where(g => g.InAddresses.Contains(tlMailbox.Address)) .Select(g => g); foreach (var mailGroup in groupsContainsMailbox) { if (mailGroup.InAddresses.Count == 1) { mailServer.DeleteMailGroup(mailGroup.Id, mailserverfactory); } else { mailGroup.RemoveMember(tlMailbox.Address.Id); } } mailServer.DeleteMailbox(tlMailbox); } catch (Exception ex) { _log.Error("RemoveTeamlabMailbox(mailboxId = {0}) Failure\r\nException: {1}", mailbox.MailBoxId, ex.ToString()); } }