Exemplo n.º 1
0
        public async Task SendEmail(OmbiUser user)
        {
            var settings = await _emailSettings.GetSettingsAsync();

            if (!settings.Enabled)
            {
                return;
            }
            var template = await _templates.GetTemplate(NotificationAgent.Email, NotificationType.WelcomeEmail);

            if (!template.Enabled)
            {
                return;
            }

            var cs = await _customizationSettings.GetSettingsAsync();

            var parsed = Parse(user, template, cs);

            var message = new NotificationMessage
            {
                Message = parsed.Message,
                Subject = parsed.Subject,
                To      = user.Email,
            };
            await _email.SendAdHoc(message, settings);
        }
Exemplo n.º 2
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.º 3
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);
        }