Exemple #1
0
        public async Task SendNewOrderEmailAsync(Order order)
        {
            var template = await emailTemplatesManager.ReadTemplateAsync(emailTemplateSettings.NewOrder.TemplateName);

            template = emailTemplateParser.PrepareNewOrderEmailAsync(order, template);
            var subject = ParseSubjectOrderId(emailTemplateSettings.NewOrder.Subject, order.Id);
            await emailManager.SendAsync(order.User.Email, order.User.FullName, subject, template);
        }
Exemple #2
0
        public async Task SendNewSalonEmailAsync(BeautySalon beautySalon)
        {
            var template = await emailTemplatesManager.ReadTemplateAsync(emailTemplateSettings.NewOrder.TemplateName);

            template = emailTemplateParser.PrepareActivateNewSalonEmail(beautySalon, template);
            var subject = ParseSubjectId(emailTemplateSettings.NewOrder.Subject, beautySalon.BeautySalonId.ToString());
            await emailManager.SendAsync(beautySalon.Email, beautySalon.ContactName, subject, template);
        }
Exemple #3
0
        public async Task <IActionResult> SendTest()
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageEmailSettings))
            {
                return(Unauthorized());
            }

            // Build breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Admin", "Plato.Admin")
                            .LocalNav()
                            ).Add(S["Settings"], settings => settings
                                  .Action("Index", "Admin", "Plato.Settings")
                                  .LocalNav()
                                  ).Add(S["Email"], email => email
                                        .Action("Index", "Admin", "Plato.Email")
                                        .LocalNav()
                                        ).Add(S["Test Email"]);
            });

            // We always need a default sender to send the test to and from
            if (string.IsNullOrEmpty(_smtpSettings.DefaultFrom))
            {
                ViewData.ModelState.AddModelError(string.Empty, "You must specify a default sender first.");
                return(await Index());
            }

            // Build message
            var message = new MailMessage(
                new MailAddress(_smtpSettings.DefaultFrom),
                new MailAddress(_smtpSettings.DefaultFrom))
            {
                Subject = "Test email from Plato",
                Body    = WebUtility.HtmlDecode(GetTestMessage())
            };

            // Send test message
            var result = await _emailManager.SendAsync(message);

            // Success?
            if (result.Succeeded)
            {
                _alerter.Success(T["Email Sent Successfully!"]);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ViewData.ModelState.AddModelError(error.Code, $"{error.Code} - {error.Description}");
                }
            }

            return(await Index());
        }
 public async Task Run([QueueTrigger(QueueName, Connection = ConnectionName)] string message, ILogger log)
 {
     log.LogInformation($"C# Queue trigger function processed: {message}");
     await emailManager.SendAsync(message);
 }
Exemple #5
0
        public async Task SendNewOrderEmailAsync(OrderDto order)
        {
            var template = await emailTemplatesManager.PrepareNewOrderEmailAsync(order);

            await emailManager.SendAsync(order.User.Email, order.User.FullName, $"New order no.{order.Id}", template);
        }
Exemple #6
0
        public async Task ExecuteAsync(object sender, SafeTimerEventArgs args)
        {
            // Polling is disabled
            if (!_smtpSettings.EnablePolling)
            {
                return;
            }

            // Get email to process
            var emails = await GetEmails();

            // We need emails to process
            if (emails == null)
            {
                return;
            }

            // Holds results to increment or delete emails
            var toDelete    = new List <int>();
            var toIncrement = new List <int>();

            // Iterate emails attempting to send
            foreach (var email in emails)
            {
                // Send the email
                var result = await _emailManager.SendAsync(email.ToMailMessage());

                // Success?
                if (result.Succeeded)
                {
                    // Queue for deletion
                    toDelete.Add(email.Id);
                }
                else
                {
                    // Log errors
                    if (_logger.IsEnabled(LogLevel.Critical))
                    {
                        foreach (var error in result.Errors)
                        {
                            _logger.LogCritical($"{error.Code} {error.Description}");
                        }
                    }

                    // Increment send attempts if we are below configured threshold
                    // Once we reach the threshold delete the email from the queue
                    if (email.SendAttempts < _smtpSettings.SendAttempts)
                    {
                        toIncrement.Add(email.Id);
                    }
                    else
                    {
                        toDelete.Add(email.Id);
                    }
                }
            }

            // Delete successfully sent
            await ProcessToDelete(toDelete.ToArray());

            // Increment send attempts for failures
            await ProcessToIncrement(toIncrement.ToArray());
        }
Exemple #7
0
        public async Task ExecuteAsync(object sender, SafeTimerEventArgs args)
        {
            // Polling is disabled
            if (!_smtpSettings.EnablePolling)
            {
                return;
            }

            // Get email to process
            var emails = await GetEmails();

            // We need emails to process
            if (emails == null)
            {
                return;
            }

            // Get all attachments for emails
            var attachments = await _emailAttachmentStore.QueryAsync()
                              .Take(int.MaxValue, false)
                              .Select <EmailAttachmentQueryParams>(q =>
            {
                q.EmailId.IsIn(emails.Select(e => e.Id).ToArray());
            })
                              .ToList();

            // Holds results to increment or delete emails
            var toDelete    = new List <int>();
            var toIncrement = new List <int>();

            // Iterate emails attempting to send
            foreach (var email in emails)
            {
                // Build mail message
                var mailMessage = email.ToMailMessage();

                // Add attachments to the email
                if (attachments?.Data != null)
                {
                    foreach (var emailAttacment in attachments.Data.Where(e => e.EmailId == email.Id))
                    {
                        mailMessage.Attachments.Add(emailAttacment.ToAttachment());
                    }
                }


                // Send the email
                var result = await _emailManager.SendAsync(mailMessage);

                // Success?
                if (result.Succeeded)
                {
                    // Queue for deletion
                    toDelete.Add(email.Id);
                }
                else
                {
                    // Log errors
                    if (_logger.IsEnabled(LogLevel.Critical))
                    {
                        foreach (var error in result.Errors)
                        {
                            _logger.LogCritical($"{error.Code} {error.Description}");
                        }
                    }

                    // Increment send attempts if we are below configured threshold
                    // Once we reach the threshold delete the email from the queue
                    if (email.SendAttempts < _smtpSettings.SendAttempts)
                    {
                        toIncrement.Add(email.Id);
                    }
                    else
                    {
                        toDelete.Add(email.Id);
                    }
                }
            }

            // Delete successfully sent
            await ProcessToDelete(toDelete.ToArray());

            // Increment send attempts for failures
            await ProcessToIncrement(toIncrement.ToArray());
        }