Skip to content

fix(email): migrate ResendEmailService from SMTP to official Resend SDK#26

Closed
Morgana-Claw wants to merge 2 commits intodevelopfrom
fix/resend-email-integration
Closed

fix(email): migrate ResendEmailService from SMTP to official Resend SDK#26
Morgana-Claw wants to merge 2 commits intodevelopfrom
fix/resend-email-integration

Conversation

@Morgana-Claw
Copy link
Copy Markdown
Collaborator

Problema

O email de boas-vindas não estava sendo enviado quando um usuário se registrava no endpoint de auth.

Causa Raiz

O estava usando (legado/deprecated) para enviar emails via SMTP do Resend (). Esta abordagem tem vários problemas:

  • é deprecated no .NET
  • Configuração de SMTP do Resend pode falhar silenciosamente
  • Não há feedback adequado de erros da API

Solução

Migração para o Resend .NET SDK oficial ( NuGet package v0.2.2), que usa a REST API do Resend.

Alterações

  1. ResendEmailService.cs - Reescrito para usar do SDK oficial
  2. ServicesCollectionExtensions.cs - Registrar no DI container com configuração adequada
  3. ClientManager.Infrastructure.csproj - Adicionar pacote v0.2.2
  4. AuthApplication.cs - Consolidar os dois duplicados em um só

Como configurar

Adicione no :

Testes

✅ 114/114 testes passando

- Replace System.Net.Mail.SmtpClient with official Resend NuGet package (v0.2.2)
- Register ResendClient in DI container with proper configuration
- Add Resend package reference to Infrastructure csproj
- Consolidate duplicate email sends in AuthApplication.RegisterAsync

The old implementation used SMTP to connect to Resend (smtp.resend.com:465)
which has known issues with .NET's deprecated SmtpClient. The official Resend
SDK uses their REST API which is more reliable and supports all email features.

All 114 tests pass.
…ed DI

- Inject IServiceScopeFactory instead of IEmailService in AuthApplication
- Create new scope in Task.Run to avoid accessing disposed scoped services
- Add Microsoft.Extensions.Logging.Abstractions package for ILogger
- Update unit tests to mock the scope factory chain

The fire-and-forget Task.Run was accessing IEmailService (Scoped) after
the request scope was disposed, causing the email service to fail silently.
Using IServiceScopeFactory ensures a valid scope for the background task.

All 94 tests pass.
@Morgana-Claw
Copy link
Copy Markdown
Collaborator Author

Superseded by PR #27. Resend SDK migration is already included in the develop branch.

@Morgana-Claw Morgana-Claw deleted the fix/resend-email-integration branch April 1, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant