Exemplo n.º 1
0
        private async Task SendIndividualEmails(MassEmailModel model, CustomizationSettings customization, EmailNotificationSettings email, List <Task> messagesSent)
        {
            var resolver = new NotificationMessageResolver();
            var curlys   = new NotificationMessageCurlys();

            foreach (var user in model.Users)
            {
                var fullUser = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == user.Id);

                if (!fullUser.Email.HasValue())
                {
                    _log.LogInformation("User {0} has no email, cannot send mass email to this user", fullUser.UserName);
                    continue;
                }
                curlys.Setup(fullUser, customization);
                var template = new NotificationTemplates()
                {
                    Message = model.Body, Subject = model.Subject
                };
                var content = resolver.ParseMessage(template, curlys);
                var msg     = new NotificationMessage
                {
                    Message = content.Message,
                    To      = fullUser.Email,
                    Subject = content.Subject
                };
                messagesSent.Add(DelayEmail(msg, email));
                _log.LogInformation("Sent mass email to user {0} @ {1}", fullUser.UserName, fullUser.Email);
            }
        }
Exemplo n.º 2
0
        public async Task Email(MassEmailModel model)
        {
            if (!model.GetEmailEnabled())
            {
                return;
            }
            var recepients = model.GetRecepients();

            if (!recepients.Any())
            {
                return;
            }

            if (model.Text.Contents == null)
            {
                throw new ArgumentNullException(nameof(model.Text.Contents));
            }

            var body = Regex.Replace(model.Text.Contents, EmailTokens.Name, MailGunRecepientName,
                                     RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            await SendEmail(recepients, $"{model.ProjectName}: {model.Subject}",
                            $@"{body}

{model.Initiator.DisplayName}
", model.Initiator.ToRecipient());
        }
Exemplo n.º 3
0
        public async Task SendMassEmail_SingleUser()
        {
            var model = new MassEmailModel
            {
                Body    = "Test",
                Subject = "Subject",
                Users   = new List <OmbiUser>
                {
                    new OmbiUser
                    {
                        Id = "a"
                    }
                }
            };

            _mocker.Setup <OmbiUserManager, IQueryable <OmbiUser> >(x => x.Users).Returns(new List <OmbiUser>
            {
                new OmbiUser
                {
                    Id    = "a",
                    Email = "*****@*****.**"
                }
            }.AsQueryable().BuildMock().Object);

            var result = await _subject.SendMassEmail(model);

            _mocker.Verify <IEmailProvider>(x => x.SendAdHoc(It.Is <NotificationMessage>(m => m.Subject == model.Subject &&
                                                                                         m.Message == model.Body &&
                                                                                         m.To == "*****@*****.**"), It.IsAny <EmailNotificationSettings>()), Times.Once);
        }
Exemplo n.º 4
0
 private void InitModel(MassEmailModel model, string selectedTab)
 {
     model.IsAdmin     = IsAdmin();
     model.SelectedTab = selectedTab;
     model.Privs       = Provider.Data.Client.GetPrivs();
     model.Communities = Provider.Data.Client.GetCommunities();
     model.Managers    = Provider.Data.Client.AllActiveManagers();
     model.Tools       = Provider.Scheduler.Resource.AllActiveResources();
     model.Areas       = Provider.Data.Room.GetPassbackRooms();
 }
Exemplo n.º 5
0
        public async Task Email(MassEmailModel model)
        {
            if (model.Text.Contents == null)
            {
                throw new ArgumentNullException(nameof(model.Text.Contents));
            }

            var body = Regex.Replace(model.Text.Contents, EmailTokens.Name, MessageService.GetRecepientPlaceholderName(),
                                     RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            await MessageService.SendEmail(model, $"{model.ProjectName}: {model.Subject}",
                                           $@"{body}

{model.Initiator.GetDisplayName()}
");
        }
Exemplo n.º 6
0
        private async Task SendBccMails(MassEmailModel model, CustomizationSettings customization, EmailNotificationSettings email, List <Task> messagesSent)
        {
            var resolver = new NotificationMessageResolver();
            var curlys   = new NotificationMessageCurlys();

            var validUsers = new List <OmbiUser>();

            foreach (var user in model.Users)
            {
                var fullUser = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == user.Id);

                if (!fullUser.Email.HasValue())
                {
                    _log.LogInformation("User {0} has no email, cannot send mass email to this user", fullUser.UserName);
                    continue;
                }

                validUsers.Add(fullUser);
            }

            if (!validUsers.Any())
            {
                return;
            }

            var firstUser = validUsers.FirstOrDefault();

            var bccAddress = string.Join(',', validUsers.Select(x => x.Email));

            curlys.Setup(firstUser, customization);
            var template = new NotificationTemplates()
            {
                Message = model.Body, Subject = model.Subject
            };
            var content = resolver.ParseMessage(template, curlys);
            var msg     = new NotificationMessage
            {
                Message = content.Message,
                Subject = content.Subject,
                Other   = new Dictionary <string, string> {
                    { "bcc", bccAddress }
                }
            };

            messagesSent.Add(_email.SendAdHoc(msg, email));
        }
Exemplo n.º 7
0
        public async Task <bool> SendMassEmail(MassEmailModel model)
        {
            var customization = await _customizationService.GetSettingsAsync();

            var email = await _emailService.GetSettingsAsync();

            var messagesSent = new List <Task>();

            if (model.Bcc)
            {
                await SendBccMails(model, customization, email, messagesSent);
            }
            else
            {
                await SendIndividualEmails(model, customization, email, messagesSent);
            }

            await Task.WhenAll(messagesSent);

            return(true);
        }
Exemplo n.º 8
0
        public async Task <bool> SendMassEmail(MassEmailModel model)
        {
            var customization = await _customizationService.GetSettingsAsync();

            var email = await _emailService.GetSettingsAsync();

            var messagesSent = new List <Task>();

            foreach (var user in model.Users)
            {
                var fullUser = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == user.Id);

                if (!fullUser.Email.HasValue())
                {
                    _log.LogInformation("User {0} has no email, cannot send mass email to this user", fullUser.UserName);
                    continue;
                }
                var resolver = new NotificationMessageResolver();
                var curlys   = new NotificationMessageCurlys();
                curlys.Setup(fullUser, customization);
                var template = new NotificationTemplates()
                {
                    Message = model.Body, Subject = model.Subject
                };
                var content = resolver.ParseMessage(template, curlys);
                var msg     = new NotificationMessage
                {
                    Message = content.Message,
                    To      = fullUser.Email,
                    Subject = content.Subject
                };
                messagesSent.Add(_email.SendAdHoc(msg, email));
                _log.LogInformation("Sent mass email to user {0} @ {1}", fullUser.UserName, fullUser.Email);
            }

            await Task.WhenAll(messagesSent);

            return(true);
        }
Exemplo n.º 9
0
        public async Task SendMassEmail_Bcc_NoEmails()
        {
            var model = new MassEmailModel
            {
                Body    = "Test",
                Subject = "Subject",
                Bcc     = true,
                Users   = new List <OmbiUser>
                {
                    new OmbiUser
                    {
                        Id = "a"
                    },
                    new OmbiUser
                    {
                        Id = "b"
                    }
                }
            };

            _mocker.Setup <OmbiUserManager, IQueryable <OmbiUser> >(x => x.Users).Returns(new List <OmbiUser>
            {
                new OmbiUser
                {
                    Id = "a",
                },
                new OmbiUser
                {
                    Id = "b",
                }
            }.AsQueryable().BuildMock().Object);

            var result = await _subject.SendMassEmail(model);

            _mocker.Verify <IEmailProvider>(x => x.SendAdHoc(It.IsAny <NotificationMessage>(), It.IsAny <EmailNotificationSettings>()), Times.Never);
        }
Exemplo n.º 10
0
        public async Task SendMassEmail_UserNoEmail()
        {
            var model = new MassEmailModel
            {
                Body    = "Test",
                Subject = "Subject",
                Users   = new List <OmbiUser>
                {
                    new OmbiUser
                    {
                        Id = "a"
                    }
                }
            };

            _mocker.Setup <OmbiUserManager, IQueryable <OmbiUser> >(x => x.Users).Returns(new List <OmbiUser>
            {
                new OmbiUser
                {
                    Id = "a",
                }
            }.AsQueryable().BuildMock().Object);

            var result = await _subject.SendMassEmail(model);

            _mocker.Verify <ILogger <MassEmailSender> >(
                x => x.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.IsAny <It.IsAnyType>(),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <It.IsAnyType, Exception, string> >()),
                Times.Once);

            _mocker.Verify <IEmailProvider>(x => x.SendAdHoc(It.IsAny <NotificationMessage>(), It.IsAny <EmailNotificationSettings>()), Times.Never);
        }
Exemplo n.º 11
0
 public async Task <bool> SendMassEmail([FromBody] MassEmailModel model)
 {
     return(await _sender.SendMassEmail(model));
 }