public async Task <IActionResult> OrderEmails([FromRoute] int eventId, [FromServices] IApplicationEmailSender emailSender, [FromServices] IRegistrationService registrationService, [FromBody] EmailVm vm) { var registrations = await registrationService.GetRegistrationsWithOrders(eventId); var emailTasks = registrations.Select(r => { var message = vm.Message; if (r.HasOrder) { StringBuilder builder = new StringBuilder(); builder.AppendLine("<br>"); builder.AppendLine("<h4>Ordre</h4>"); r.Orders.ForEach( (o) => o.OrderLines?.ForEach( (line) => builder.AppendLine($"<br>{line.ProductName}") ) ); message += builder.ToString(); } return(emailSender .SendStandardEmailAsync( $"{r.ParticipantName} <{r.User.Email}>", vm.Subject, message)); }); await Task.WhenAll(emailTasks); return(Ok()); }
public async Task SendCertificateAsync(Certificate certificate, CancellationToken cancellationToken = default) { var pdfStream = await _certificateRenderer .RenderToPdfAsStreamAsync(new CertificateViewModel(certificate)); var memoryStream = new MemoryStream(); await pdfStream.CopyToAsync(memoryStream, cancellationToken); await _emailSender.SendStandardEmailAsync(certificate.RecipientEmail, $"Kursbevis for {certificate.Title}", "Her er kursbeviset! Gratulere!", new Attachment { Filename = "kursbevis.pdf", ContentType = MediaTypeNames.Application.Pdf, Bytes = memoryStream.ToArray() }); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { ReturnUrl = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { Name = Input.Name, UserName = Input.Email, Email = Input.Email, PhoneNumber = Input.Phone }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); var subject = "En liten bekreftelse bare..."; var message = $@"<p>Vi har snart laget en ny bruker til deg, men vil bare at du bekrefter med å trykke på lenken!</p> <p><a href='{callbackUrl}'>Bekreft her</a></p> <p></p> <p>Hvis lenken ikke virker, så kan du kopiere inn teksten under i nettleseren: {callbackUrl} </p>" ; await _emailSender.SendStandardEmailAsync($"{Input.Name} <{Input.Email}>", subject, message); return(RedirectToPage("/Info/EmailSent")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } var registration = await _registrationService.GetWithUserAndEventInfoAsync(id.Value); if (registration == null) { return(NotFound()); } if (HttpContext.Request.Query["auth"] == registration.VerificationCode) { if (registration.Status == RegistrationStatus.Draft || registration.Status == RegistrationStatus.Cancelled) { await _registrationService.SetRegistrationAsVerified(id.Value); } // Send a copy to admin TODO: Read from appsettings var adminmessage = "<p>Hurra! Enda en påmelding!</p>"; await _registrationEmailSender.SendRegistrationAsync("*****@*****.**", $"KOPI: Påmelding {registration.EventInfo.Title}", adminmessage, registration.RegistrationId); // Send welcome letter to participant await _standardEmailSender.SendStandardEmailAsync( $@"{registration.ParticipantName} <{registration.User.Email}>", $@"Velkommen til {registration.EventInfo.Title}!", registration.EventInfo.WelcomeLetter); return(RedirectToPage("./Confirmed")); } // If we came here, something has went wrong. return(RedirectToPage("./Failed")); }