Exemple #1
0
 public Email[] GetAllEmailsFromList()
 {
     using (EmailDbContext emaildb = new EmailDbContext())
     {
         return(emaildb.Emails.Where(x => x.U_Id == userid && x.Emlist_Id == emaillistid).ToArray());
     }
 }
Exemple #2
0
 public string[] GetEmailAddresses()
 {
     using (EmailDbContext emaildb = new EmailDbContext())
     {
         return(emaildb.Emails.Where(x => x.U_Id == userid && x.Emlist_Id == emaillistid).Select(x => x.Email_Add).ToArray());
     }
 }
Exemple #3
0
 public void Update()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         Email email = db.Emails.Where(x => x.U_Id == userid && x.Eml_Id == emailid).FirstOrDefault();
         try
         {
             if (firstname != email.F_Name)
             {
                 email.F_Name = firstname;
             }
             else if (lastname != email.L_Name)
             {
                 email.L_Name = lastname;
             }
             else if (emailaddress != "")
             {
                 email.Email_Add = emailaddress;
             }
             db.SaveChanges();
             ProecessSuccess?.Invoke(null, null);
         }
         catch (Exception ex)
         {
             ProcessFailDelegate Failed = ProcessFail;
             Failed?.Invoke("Failed" + Environment.NewLine + ex.ToString());
         }
     }
 }
Exemple #4
0
 public EmailController(ILogger <EmailController> logger, IMapper mapper, EmailDbContext dbContext, IOptions <AppSettings> appSettings)
 {
     _logger      = logger;
     _mapper      = mapper;
     _dbContext   = dbContext;
     _appSettings = appSettings;
 }
Exemple #5
0
 public Email GetEmail()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         return(db.Emails.Where(x => x.U_Id == userid && x.Eml_Id == emailid).First());
     }
 }
Exemple #6
0
 public void Add()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         try
         {
             Email email = new Email()
             {
                 F_Name    = firstname,
                 L_Name    = lastname,
                 Email_Add = emailaddress,
                 Eml_Id    = emailid,
                 U_Id      = userid
             };
             db.Emails.Add(email);
             db.SaveChangesAsync();
             ProecessSuccess?.Invoke(null, null);
         }
         catch (Exception ex)
         {
             ProcessFailDelegate Failed = ProcessFail;
             Failed?.Invoke("Failed" + Environment.NewLine + ex.ToString());
         }
     }
 }
Exemple #7
0
 public List <Email> GetAllEmails()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         return(db.Emails.Where(x => x.U_Id == userid).ToList());
     }
 }
Exemple #8
0
        /// <summary>
        /// Uses InMemoryDatabase to create a mock database for each test
        /// </summary>
        public SendMailTestBase()
        {
            var options = new DbContextOptionsBuilder <EmailDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            _context = new EmailDbContext(options);
            _context.Database.EnsureCreated();
        }
        public AccountController(UserManager <AppUser> userManager
                                 , SignInManager <AppUser> signInManager
                                 , IPasswordHasher <AppUser> passwordHasher
                                 , EmailDbContext db
                                 )
        {
            _userManager    = userManager;
            _signInManager  = signInManager;
            _passwordHasher = passwordHasher;
            _db             = db;

            //_passwordValidator = passwordValidator;
        }
Exemple #10
0
 public void Delete()
 {
     using (EmailDbContext db = new EmailDbContext())
     {
         try
         {
             Email email = db.Emails.Where(x => x.U_Id == userid && x.Eml_Id == emailid).FirstOrDefault();
             db.Emails.Remove(email);
             db.SaveChangesAsync();
             ProecessSuccess?.Invoke(null, null);
         }
         catch (Exception ex)
         {
             ProcessFailDelegate Failed = ProcessFail;
             Failed?.Invoke("Failed" + Environment.NewLine + ex.ToString());
         }
     }
 }
Exemple #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, EmailDbContext _context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();

            if (!_context.Database.EnsureCreated())
            {
                _context.Database.Migrate();
            }
        }
Exemple #12
0
        public void GetItems_ReturnsSingleItem()
        {
            var builder = new DbContextOptionsBuilder <EmailDbContext>();

            builder.UseInMemoryDatabase <EmailDbContext>(Guid.NewGuid().ToString());
            var options = builder.Options;

            using (var context = new EmailDbContext(options))
            {
                var orders = new List <Email>
                {
                    new Email {
                        Id = 33, Subject = "Email Subject"
                    },
                };

                context.Emails.AddRange(orders);
                context.SaveChanges();
            }

            using (var context = new EmailDbContext(options))
            {
                var loggerMock   = new Mock <ILogger <EmailController> >();
                var config       = new MapperConfiguration(cfg => cfg.AddProfile <AutoMapping>());
                var mapper       = config.CreateMapper();
                var settingsMock = new Mock <IOptions <AppSettings> >();
                var controller   = new EmailController(loggerMock.Object, mapper, context, settingsMock.Object);
                var result       = controller.Get();

                var okResult = result as OkObjectResult;

                // assert
                Assert.NotNull(okResult);
                Assert.True(okResult is OkObjectResult);
                Assert.IsType <List <EmailDTO> >(okResult.Value);

                Assert.Equal(StatusCodes.Status200OK, okResult.StatusCode);
                var collection = okResult.Value as List <EmailDTO>;
                Assert.Single(collection);
            }
        }
Exemple #13
0
 public AuthService(EmailDbContext context, ILoggerFactory logger)
 {
     _logger  = logger.CreateLogger <AuthService>();
     _clients = context.Set <ServiceClient>();
 }
Exemple #14
0
 public StatusService(EmailDbContext dbContext, ILoggerFactory logger)
 {
     _logger = logger.CreateLogger <StatusService>();
     _emails = dbContext.Set <EmailTrail>();
 }
Exemple #15
0
 public EmailTemplateRepository(EmailDbContext context, ILogger <EmailTemplateRepository> logger)
 {
     _context = context;
     _logger  = logger;
 }
 public EmailProviderRepository(EmailDbContext context, ILogger <IEmailProviderRepository> logger)
 {
     _context = context;
     _logger  = logger;
 }
Exemple #17
0
 public AdminService()
 {
     _db    = new EmailDbContext();
     client = new RedisClient(RedisIP, RedisPort);
 }
Exemple #18
0
 public Essential()
 {
     _context = new EmailDbContext();
 }
 public EmailController(EmailDbContext db)
 {
     _db = db;
 }
Exemple #20
0
        public static void Send(MailMessage message)
        {
            // Queue an e-mail to send later
            using (EmailDbContext db = new EmailDbContext())
            {
                try
                {
                    EmailMessage emailMessage = new EmailMessage
                    {
                        Id         = Guid.NewGuid(),
                        From       = ((message.From == null) ? (new MailAddress("*****@*****.**", "Doug Lockwood's Application")).ToString() : message.From.ToString()),
                        To         = message.To.ToString(),
                        Cc         = message.CC.ToString(),
                        Bcc        = message.Bcc.ToString(),
                        Subject    = message.Subject,
                        Body       = message.Body,
                        IsBodyHtml = message.IsBodyHtml,
                        ReplyTo    = message.ReplyToList.ToString(),
                        Created    = DateTime.Now,
                        Expires    = DateTime.Now.AddDays(_daysToExpiration)
                    };

                    db.Email.Add(emailMessage);
                    db.SaveChanges();
                }
                catch
                {
                    throw;
                }
            }
            ////// Send an e-mail
            ////SmtpClient client = new SmtpClient
            ////{
            ////    Host = "host276.hostmonster.com",
            ////    Credentials = new NetworkCredential("*****@*****.**", "D0ugl@$L"),
            ////};

            ////message.From = new MailAddress("*****@*****.**");

            ////if (message.IsBodyHtml)
            ////{
            ////    message.Body = message.Body.Replace(@"\r\n", "<br/>");
            ////}

            ////message.Body +=
            ////    ((message.IsBodyHtml) ? "<p>&nbsp;</p><hr/><footer><p>" : "\r\n\r\n--------------------\r\n")
            ////    + "This message was sent by McREL International through an unmonitored e-mail address. Please do not reply to this e-mail."
            ////    + ((message.IsBodyHtml) ? "</p><p>" : "\r\n\r\n")
            ////    + "You can learn more about McREL International by visiting us "
            ////    + ((message.IsBodyHtml) ? "<a href=\"http://www.mcrel.org\">online</a>.</p><p>" : "online at http://www.mcrel.org.\r\n\r\n")
            ////    + "McREL International"
            ////    + ((message.IsBodyHtml) ? "<br/>" : "\r\n")
            ////    + "4601 DTC Boulevard, Suite 500"
            ////    + ((message.IsBodyHtml) ? "<br/>" : "\r\n")
            ////    + "Denver, CO 80237-2596"
            ////    + ((message.IsBodyHtml) ? "<br/>" : "\r\n")
            ////    + "P: 303.337.0990"
            ////    + ((message.IsBodyHtml) ? "<br/>" : "\r\n")
            ////    + "F: 303.337.3005"
            ////    + ((message.IsBodyHtml) ? "<br/>" : "\r\n")
            ////    + "*****@*****.**"
            ////    + ((message.IsBodyHtml) ? "<br/>" : "\r\n")
            ////    + ((message.IsBodyHtml) ? "<a href=\"http://www.mcrel.org\">www.mcrel.org</a>" : "http://www.mcrel.org")
            ////    + ((message.IsBodyHtml) ? "</p></footer>" : "\r\n--------------------\r\n")
            ////    ;


            ////client.Send(message);
        }
 public EmailRepository(EmailDbContext context)
 {
     _context = context;
 }
Exemple #22
0
        public async Task <string> FunctionHandler(SNSEvent snsEvent, ILambdaContext context)
        {
            string   mongoConnectionString = Environment.GetEnvironmentVariable("MongoDB_ConnectionString");
            DateTime now = DateTime.UtcNow;

            XmlConfigurator.Configure(m_logRepo, new System.IO.FileInfo("log4net.config"));
            foreach (var record in snsEvent.Records)
            {
                var     snsRecord = record.Sns;
                JObject message   = JObject.Parse(snsRecord.Message);
                string  notificationId;

                switch (message["notificationType"].ToString())
                {
                case "Bounce":
                    notificationId = message["bounce"]["feedbackId"].ToString();
                    break;

                case "Complaint":
                    notificationId = message["complaint"]["feedbackId"].ToString();
                    break;

                default:
                    notificationId = "";
                    break;
                }

                m_log.Info($"[{record.EventSource} {snsRecord.Timestamp}] Message = {snsRecord.Message}");
                if (!String.IsNullOrEmpty(mongoConnectionString))
                {
                    string         mongoDatabaseName = mongoConnectionString.Substring(mongoConnectionString.LastIndexOf("/") + 1);
                    MongoClient    mongoClient       = new MongoClient(mongoConnectionString);
                    IMongoDatabase mongoDatabase     = mongoClient.GetDatabase(mongoDatabaseName);
                    IMongoCollection <EmailNotificationLog> emailNotificationLogCollection = mongoDatabase.GetCollection <EmailNotificationLog>("EmailNotificationLog");
                    IMongoCollection <EmailBlackList>       emailBlackListCollection       = mongoDatabase.GetCollection <EmailBlackList>("EmailBlackList");

                    emailBlackListCollection.Indexes.CreateOne(new BsonDocument("EmailAddress", 1), new CreateIndexOptions {
                        Name = "UX_EmailBlackList_EmailAddress", Unique = true
                    });
                    await emailNotificationLogCollection.InsertOneAsync(new EmailNotificationLog {
                        NotificationType = message["notificationType"].ToString(),
                        NotificationId   = notificationId,
                        Event            = BsonSerializer.Deserialize <BsonDocument>(snsRecord.Message),
                        Timestamp        = snsRecord.Timestamp,
                        Created          = now
                    });

                    if ((message["notificationType"].ToString() == "Bounce") && (message["bounce"]["bounceType"].ToString() == "Permanent"))
                    {
                        foreach (JObject bouncedRecipient in message["bounce"]["bouncedRecipients"])
                        {
                            string emailAddress = bouncedRecipient["emailAddress"].ToString().ToLower();
                            long   count        = await emailBlackListCollection.Find(Builders <EmailBlackList> .Filter.Where(x => x.EmailAddress == emailAddress)).CountAsync();

                            if (count == 0)
                            {
                                await emailBlackListCollection.InsertOneAsync(new EmailBlackList {
                                    EmailAddress = emailAddress,
                                    Created      = now
                                });
                            }
                        }
                    }
                }
                if (EmailDbContext.IsActive())
                {
                    using (var db = new EmailDbContext()) {
                        var emailNotificationLog = new EmailNotificationLog {
                            NotificationType = message["notificationType"].ToString(),
                            NotificationId   = notificationId,
                            Message          = snsRecord.Message,
                            Timestamp        = snsRecord.Timestamp,
                            Created          = now
                        };

                        db.EmailNotificationLog.Add(emailNotificationLog);
                        if ((message["notificationType"].ToString() == "Bounce") && (message["bounce"]["bounceType"].ToString() == "Permanent"))
                        {
                            foreach (JObject bouncedRecipient in message["bounce"]["bouncedRecipients"])
                            {
                                string emailAddress = bouncedRecipient["emailAddress"].ToString().ToLower();

                                if (db.EmailBlackList.Where(x => x.EmailAddress == emailAddress).Count() == 0)
                                {
                                    var emailBlackList = new EmailBlackList {
                                        EmailAddress = emailAddress,
                                        Created      = now
                                    };

                                    db.EmailBlackList.Add(emailBlackList);
                                }
                            }
                        }
                        db.SaveChanges();
                    }
                }
            }
            return("okay");
        }
Exemple #23
0
 public HomeController(EmailDbContext dbContext, UserManager <AppUser> userManager)
 {
     db           = dbContext;
     _userManager = userManager;
 }
 public MailService(IServiceProvider serviceProvider, ILogger <MailService> logger, EmailDbContext emailDbContext)
 {
     _serviceProvider = serviceProvider;
     _logger          = logger;
     _emailDbContext  = emailDbContext;
 }
Exemple #25
0
 public RabbitService(EmailDbContext dbContext, ILoggerFactory logger)
 {
     _logger    = logger.CreateLogger <RabbitService>();
     _emails    = dbContext.Set <EmailTrail>();
     _dbContext = dbContext;
 }