IdentityEmailSender.cs 2.7 KB

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