Beispiel #1
0
        public virtual async Task <bool> Handle(SendMailCommand command, CancellationToken cancellationToken)
        {
            // Get mail service.
            IMailClient mailClient = null;

            if (command.UseMailServiceName)
            {
                mailClient = await _mailClientsManager.GetMailClientAsync(command.MailServiceName, cancellationToken);
            }
            else
            {
                mailClient = await _mailClientsManager.GetActiveMailClientAsync(cancellationToken);
            }

            if (mailClient == null)
            {
                return(false);
            }

            var mailSender        = (IMailAddress)command.Sender;
            var recipients        = command.Recipients?.Select(recipient => (IMailAddress)recipient).ToArray();
            var carbonCopies      = command.CarbonCopies?.Select(carbonCopy => (IMailAddress)carbonCopy).ToArray();
            var blindCarbonCopies = command.BlindCarbonCopies?.Select(blindCarbonCopy => (IMailAddress)blindCarbonCopy)
                                    .ToArray();

            await mailClient
            .SendMailAsync(mailSender, recipients, carbonCopies, blindCarbonCopies, command.Subject,
                           command.Content, command.IsHtml, command.AdditionalSubjectData, command.AdditionalContentData,
                           null,
                           cancellationToken);

            return(true);
        }