Exemple #1
0
        public async Task SendBulkEmailToAllDeacons(AnnouncementViewModel viewModel, string username)
        {
            var user          = _unitOfWork.AppUserRepository.FindUserByEmail(username);
            var deacons       = _unitOfWork.AppUserRepository.FindUsersByRole(enums.AppUserRole.Deacon);
            var emailContacts = new List <EmailContact>();

            var emailClient = new EmailWrapperClient();

            var email = new EmailContact
            {
                FromEmailAddress = user.EmailAddress,
                Subject          = viewModel.Title,
                PlainTextBody    = HtmlRemoval.ConvertHtmlToPlainText(viewModel.AnnouncementHtml),
                HtmlBody         = viewModel.AnnouncementHtml
            };

            foreach (var deacon in deacons)
            {
                emailContacts.Add(new EmailContact
                {
                    ToEmailAddress = deacon.EmailAddress,
                    ReceiverName   = deacon.FullName
                });
            }

            var response = await emailClient.SendMultipleEmailsAsync(emailContacts, email);
        }
Exemple #2
0
        public async Task <EmailViewModel> SendBulkEmailsAsync(EmailViewModel emailViewModel, EmailWrapperClient client, string username)
        {
            Response response;
            var      bulkContacts = GetBulkEmailContacts(emailViewModel);

            try
            {
                response = await client.SendMultipleEmailsAsync(bulkContacts, emailViewModel.EmailContact);

                if (IsResponseOk(response))
                {
                    //GetStatusNotification(EmailStatus.BulkEmailsDelivered);
                    emailViewModel.StatusNotification    = GetStatusNotification(EmailStatus.BulkEmailsDelivered);
                    emailViewModel.EmailContact.DateSent = DateTime.Now;
                    StoreBulkEmailContacts(bulkContacts, username);
                }
                else
                {
                    //GetStatusNotification(EmailStatus.BulkEmailsNotDelivered);
                    emailViewModel.StatusNotification = GetStatusNotification(EmailStatus.BulkEmailsNotDelivered);
                }
            }
            catch (Exception ex)
            {
                // log caught exception with Elmah
                ErrorSignal.FromCurrentContext().Raise(ex);

                emailViewModel.StatusNotification = GetStatusNotification(EmailStatus.BulkEmailsNotDelivered);
            }

            if (emailViewModel.StatusNotification != null)
            {
                emailViewModel.HasStatusNotification = true;
            }
            return(emailViewModel);
        }