public void SendNewsletter(NewsletterDTO newsletter, IEnumerable <AppUser> users, MailParams parameters) { if (string.IsNullOrWhiteSpace(newsletter.Text)) { return; } foreach (var idHolder in newsletter.UserIds) { string userEmail = users.Where(x => x.Id == idHolder.Id).First().Email; SendLetter(newsletter.Text, userEmail, parameters); } }
public IActionResult Post([FromBody] NewsletterDTO newsletter) { List <AppUser> users = _userManager.Users.ToList(); MailParams parameters = new MailParams() { Host = Configuration["Mail:Host"], Port = int.Parse(Configuration["Mail:Port"]), UserName = Configuration["Mail:UserName"], UserPassword = Configuration["Mail:UserPassword"] }; Task.Run(() => _mailService.SendNewsletter(newsletter, users, parameters)); return(Ok()); }