feat(backend): Implement email service infrastructure for Day 7

Add complete email service infrastructure with Mock and SMTP implementations.

Changes:
- Created EmailMessage domain model for email data
- Added IEmailService interface for email sending
- Implemented MockEmailService for development/testing (logs emails)
- Implemented SmtpEmailService for production SMTP sending
- Added IEmailTemplateService interface for email templates
- Implemented EmailTemplateService with HTML templates for verification, password reset, and invitation emails
- Registered email services in DependencyInjection with provider selection
- Added email configuration to appsettings.Development.json (Mock provider by default)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2025-11-03 21:16:11 +01:00
parent a220e5d5d7
commit 921990a043
8 changed files with 362 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
using ColaFlow.Modules.Identity.Domain.Services;
namespace ColaFlow.Modules.Identity.Application.Services;
/// <summary>
/// Service for sending emails
/// </summary>
public interface IEmailService
{
/// <summary>
/// Sends an email message
/// </summary>
/// <param name="message">The email message to send</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>True if email was sent successfully, false otherwise</returns>
Task<bool> SendEmailAsync(EmailMessage message, CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,37 @@
namespace ColaFlow.Modules.Identity.Application.Services;
/// <summary>
/// Service for rendering email templates
/// </summary>
public interface IEmailTemplateService
{
/// <summary>
/// Renders a verification email template
/// </summary>
/// <param name="recipientName">Name of the recipient</param>
/// <param name="verificationUrl">URL for email verification</param>
/// <returns>HTML email body</returns>
string RenderVerificationEmail(string recipientName, string verificationUrl);
/// <summary>
/// Renders a password reset email template
/// </summary>
/// <param name="recipientName">Name of the recipient</param>
/// <param name="resetUrl">URL for password reset</param>
/// <returns>HTML email body</returns>
string RenderPasswordResetEmail(string recipientName, string resetUrl);
/// <summary>
/// Renders a tenant invitation email template
/// </summary>
/// <param name="recipientName">Name of the recipient</param>
/// <param name="tenantName">Name of the tenant</param>
/// <param name="inviterName">Name of the person who sent the invitation</param>
/// <param name="invitationUrl">URL for accepting the invitation</param>
/// <returns>HTML email body</returns>
string RenderInvitationEmail(
string recipientName,
string tenantName,
string inviterName,
string invitationUrl);
}