public static TMessage Create <TMessage>(INotificationRecipient recipient, params INotificationRecipient[] recipients) where TMessage : NotificationMessage, new() { var message = Activator.CreateInstance <TMessage>(); message.Recipients = recipients.Prepend(recipient).ToArray(); if (TryGetBody <TMessage>("html", out var htmlBody)) { message.Body = htmlBody; message.Html = true; } else if (TryGetBody <TMessage>("text", out var textBody)) { message.Body = textBody; message.Html = false; } return(message); }
private async IAsyncEnumerable <string> ResolveRecipientEmailAddressesAsync(INotificationRecipient recipient) { if (recipient.Address?.IsEMail() ?? false) { yield return(recipient.Address); } else if (recipient.Address?.IsGuid() ?? false) { var address = await graphService .GetMailAddressAsync(recipient.Address) .ConfigureAwait(false); if (string.IsNullOrEmpty(address)) { var memberIds = graphService .GetGroupMembersAsync(recipient.Address, true) .ConfigureAwait(false); await foreach (var memberId in memberIds) { address = await graphService .GetMailAddressAsync(recipient.Address) .ConfigureAwait(false); if (!string.IsNullOrEmpty(address)) { yield return(address); } } } else { yield return(address); } } }