IdentityEmailSender.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Application.Abstractions.Messaging.Email;
  2. using Infrastructure.Persistence.Identity;
  3. using Microsoft.AspNetCore.Identity.UI.Services;
  4. namespace Infrastructure.Messaging.Email
  5. {
  6. public class IdentityEmailSender : IEmailSender
  7. {
  8. private readonly IMailService _mailService;
  9. public IdentityEmailSender(IMailService mailService)
  10. {
  11. _mailService = mailService;
  12. }
  13. public async Task SendEmailAsync(string email, string subject, string htmlMessage)
  14. {
  15. ArgumentException.ThrowIfNullOrWhiteSpace(email);
  16. ArgumentException.ThrowIfNullOrWhiteSpace(subject);
  17. ArgumentNullException.ThrowIfNull(htmlMessage);
  18. await _mailService.SendAsync(
  19. new SendData(
  20. ToAddress: email,
  21. Subject: subject,
  22. MessageHtml: htmlMessage
  23. )
  24. );
  25. }
  26. public Task SendConfirmationLinkAsync(ApplicationUser user, string email, string confirmationLink)
  27. {
  28. ArgumentNullException.ThrowIfNull(user);
  29. ArgumentException.ThrowIfNullOrWhiteSpace(email);
  30. ArgumentException.ThrowIfNullOrWhiteSpace(confirmationLink);
  31. return _mailService.SendAsync(new SendData(
  32. ToAddress: email,
  33. Subject: "이메일 확인",
  34. MessageHtml: $"""
  35. <p>아래 링크를 눌러 이메일 확인을 완료하세요.</p>
  36. <p><a href="{confirmationLink}">이메일 확인</a></p>
  37. """
  38. ));
  39. }
  40. public Task SendPasswordResetLinkAsync(ApplicationUser user, string email, string resetLink)
  41. {
  42. ArgumentNullException.ThrowIfNull(user);
  43. ArgumentException.ThrowIfNullOrWhiteSpace(email);
  44. ArgumentException.ThrowIfNullOrWhiteSpace(resetLink);
  45. return _mailService.SendAsync(new SendData(
  46. ToAddress: email,
  47. Subject: "비밀번호 재설정",
  48. MessageHtml: $"""
  49. <p>아래 링크를 눌러 비밀번호를 재설정하세요.</p>
  50. <p><a href="{resetLink}">비밀번호 재설정</a></p>
  51. """
  52. ));
  53. }
  54. public Task SendPasswordResetCodeAsync(ApplicationUser user, string email, string resetCode)
  55. {
  56. ArgumentNullException.ThrowIfNull(user);
  57. ArgumentException.ThrowIfNullOrWhiteSpace(email);
  58. ArgumentException.ThrowIfNullOrWhiteSpace(resetCode);
  59. return _mailService.SendAsync(new SendData(
  60. ToAddress: email,
  61. Subject: "비밀번호 재설정 코드",
  62. MessageHtml: $"""
  63. <p>비밀번호 재설정 코드:</p>
  64. <pre>{resetCode}</pre>
  65. """
  66. ));
  67. }
  68. }
  69. }