public async Task <bool> SendAsync(EmailData emailData)
        {
            var sender = _fluentEmail
                         .To(emailData.To)
                         .Subject(emailData.Subject);

            if (!string.IsNullOrEmpty(emailData.Template))
            {
                var tplNamespace = $"{_mailSettings.EmailTemplatesNamespace}.{emailData.Template}.cshtml";
                sender.UsingTemplateFromEmbedded(tplNamespace, emailData.Model.ToExpando(), _mailSettings.EmailTemplatesDiscoveryType.Assembly);
            }
            else if (emailData.BodyDelegate != null)
            {
                sender.Body(emailData.BodyDelegate());
            }
            else
            {
                sender.Body(emailData.Body);
            }

            var result = await sender.SendAsync();

            if (result.Successful)
            {
                return(true);
            }
            _notificationContext.AddNotifications(result.ErrorMessages.ToArray());
            return(false);
        }
        public Task <bool> SendAsync(EmailData emailData)
        {
            var link = emailData.Model?.GetType().GetProperty("Link")?.GetValue(emailData.Model, null);

            _logger.LogInformation($"Email sent to: {emailData.To} [{emailData.Subject}] {link}");

            return(Task.FromResult(true));
        }
 private void Clear()
 {
     _emailData = new EmailData();
 }
Ejemplo n.º 4
0
 public void Add(EmailData emailData)
 {
     Emails ??= new List <EmailData>();
     Emails.Add(emailData);
 }