public string GetHostnameFromExternalDatabase(string connectionString, string ip) { DemandPermission(); var dbContextOptionsBuilder = new DbContextOptionsBuilder <MailDbContext>(); var options = dbContextOptionsBuilder //.UseMySql(connectionString) .UseNpgsql(connectionString) .UseLoggerFactory(LoggerFactory) .Options; using var mailDbContext = new MailDbContext(options); if (!IPAddress.TryParse(ip, out var ipAddress)) { return(ip); } var hostname = mailDbContext.GreyListingWhiteList .Where(r => r.Source == "SenderIP:" + ip) .Select(r => r.Comment) .FirstOrDefault(); return(hostname); }
public string[] GetDataFromExternalDatabase(string dbid, string connectionString, string ip) { DemandPermission(); var dbContextOptionsBuilder = new DbContextOptionsBuilder <MailDbContext>(); var options = dbContextOptionsBuilder .UseMySql(connectionString) .UseLoggerFactory(LoggerFactory) .Options; using var mailDbContext = new MailDbContext(options); var token = mailDbContext.ApiKeys .Where(r => r.Id == 1) .Select(r => r.AccessToken) .FirstOrDefault(); string hostname; if (IPAddress.TryParse(ip, out var ipAddress)) { hostname = mailDbContext.GreyListingWhiteList .Where(r => r.Source == "SenderIP:" + ip) .Select(r => r.Comment) .FirstOrDefault(); } else { hostname = ip; } return(new[] { token, hostname }); }
public string GetTokenFromExternalDatabase(string connectionString) { DemandPermission(); var dbContextOptionsBuilder = new DbContextOptionsBuilder <MailDbContext>(); var options = dbContextOptionsBuilder .UseMySql(connectionString) .UseLoggerFactory(LoggerFactory) .Options; using var mailDbContext = new MailDbContext(options); var token = mailDbContext.ApiKeys .Where(r => r.Id == 1) .Select(r => r.AccessToken) .FirstOrDefault(); return(token); }
public EmailService(MailDbContext context) { _context = context; }
public void UpdateDataFromInternalDatabase(string hostname, MailServerInfo mailServer) { DemandPermission(); using var transaction = MailDbContext.Database.BeginTransaction(); var mailboxProvider = new MailboxProvider { Id = 0, Name = hostname }; var pReq = MailDbContext.MailboxProvider.Add(mailboxProvider); MailDbContext.SaveChanges(); mailboxProvider = pReq.Entity; var providerId = mailboxProvider.Id; var mailboxServer = new MailboxServer { Id = 0, IdProvider = providerId, Type = "smtp", Hostname = hostname, Port = 587, SocketType = "STARTTLS", UserName = "******", Authentication = "", IsUserData = false }; var req = MailDbContext.MailboxServer.Add(mailboxServer); MailDbContext.SaveChanges(); mailboxServer = req.Entity; var smtpServerId = mailboxServer.Id; mailboxServer = new MailboxServer { Id = 0, IdProvider = providerId, Type = "imap", Hostname = hostname, Port = 143, SocketType = "STARTTLS", UserName = "******", Authentication = "", IsUserData = false }; req = MailDbContext.MailboxServer.Add(mailboxServer); MailDbContext.SaveChanges(); mailboxServer = req.Entity; var imapServerId = mailboxServer.Id; var mailServerData = MailDbContext.ServerServer.FirstOrDefault(); var connectionString = Newtonsoft.Json.JsonConvert.SerializeObject(mailServer); var server = new ServerServer { Id = 0, MxRecord = hostname, ConnectionString = connectionString, ServerType = 2, SmtpSettingsId = smtpServerId, ImapSettingsId = imapServerId }; MailDbContext.ServerServer.Add(server); MailDbContext.SaveChanges(); if (mailServerData != null) { server = MailDbContext.ServerServer.Where(r => r.Id == mailServerData.Id).FirstOrDefault(); MailDbContext.ServerServer.Remove(server); MailDbContext.SaveChanges(); providerId = MailDbContext.MailboxServer .Where(r => r.Id == mailServerData.SmtpSettingsId) .Select(r => r.IdProvider) .FirstOrDefault(); var providers = MailDbContext.MailboxProvider.Where(r => r.Id == providerId).ToList(); MailDbContext.MailboxProvider.RemoveRange(providers); MailDbContext.SaveChanges(); var servers = MailDbContext.MailboxServer .Where(r => new[] { mailServerData.SmtpSettingsId, mailServerData.ImapSettingsId }.Any(a => a == r.Id)) .ToList(); MailDbContext.MailboxServer.RemoveRange(servers); MailDbContext.SaveChanges(); var mailboxId = MailDbContext.Mailbox .Where(r => r.IdSmtpServer == mailServerData.SmtpSettingsId) .Where(r => r.IdInServer == mailServerData.ImapSettingsId) .ToArray(); foreach (var m in mailboxId) { m.IdSmtpServer = smtpServerId; m.IdInServer = imapServerId; } MailDbContext.SaveChanges(); } transaction.Commit(); MailServiceHelperStorage.Remove(); }
public EmailingService(MailDbContext db, IMapper mapper) { _mapper = mapper; _db = db; }
public MailRepository(MailDbContext context) { _context = context; }
public GenericRepository(MailDbContext dbContext) { _dbContext = dbContext; }
public TrackController(FileContentResult pixelResponse, MailDbContext context) { this._pixelResponse = pixelResponse; _context = context; }