Table of Contents

Class ProjectNotificationEmailSender

Namespace
Builvero.Infrastructure.Services
Assembly
Builvero.Infrastructure.dll

Implementation of IProjectNotificationEmailSender using SendGrid's dynamic templates for project-related email notifications.

public class ProjectNotificationEmailSender : IProjectNotificationEmailSender
Inheritance
ProjectNotificationEmailSender
Implements
Inherited Members

Remarks

This service handles all project-related email notifications:

  • Project invitations (sent to invitees)
  • Project invitation accepted notifications (sent to inviters)
  • Project invitation declined notifications (sent to inviters)
  • Project join requests (sent to project owners)
  • Project join request approved notifications (sent to requesters)
  • Project join request declined notifications (sent to requesters)

All emails use SendGrid dynamic templates configured via SendGridOptions. The API key is resolved using ISendGridApiKeyResolver which supports environment variables, AWS SSM Parameter Store, or direct configuration.

Email addresses are validated using a regex pattern: ^[^@\s]+@[^@\s]+\.[^@\s]+$

Constructors

ProjectNotificationEmailSender(ISendGridApiKeyResolver, IOptions<SendGridOptions>, ILogger<ProjectNotificationEmailSender>)

Initializes a new instance of the ProjectNotificationEmailSender class.

public ProjectNotificationEmailSender(ISendGridApiKeyResolver apiKeyResolver, IOptions<SendGridOptions> options, ILogger<ProjectNotificationEmailSender> logger)

Parameters

apiKeyResolver ISendGridApiKeyResolver

Service for resolving SendGrid API key from various sources.

options IOptions<SendGridOptions>

SendGrid configuration options including template IDs and sender information.

logger ILogger<ProjectNotificationEmailSender>

Logger for recording email operations and errors.

ProjectNotificationEmailSender(ISendGridApiKeyResolver, IOptions<SendGridOptions>, ILogger<ProjectNotificationEmailSender>, Func<string, ISendGridClientWrapper>)

Initializes a new instance of the ProjectNotificationEmailSender class with a custom client factory (for testing).

public ProjectNotificationEmailSender(ISendGridApiKeyResolver apiKeyResolver, IOptions<SendGridOptions> options, ILogger<ProjectNotificationEmailSender> logger, Func<string, ISendGridClientWrapper> clientFactory)

Parameters

apiKeyResolver ISendGridApiKeyResolver

Service for resolving SendGrid API key from various sources.

options IOptions<SendGridOptions>

SendGrid configuration options including template IDs and sender information.

logger ILogger<ProjectNotificationEmailSender>

Logger for recording email operations and errors.

clientFactory Func<string, ISendGridClientWrapper>

Factory function for creating SendGrid client instances (allows mocking in tests).

Methods

SendProjectInvitationAcceptedAsync(ProjectInvitation, Project, User, User, CancellationToken)

Sends a notification email to the inviter when an invitation is accepted.

public Task SendProjectInvitationAcceptedAsync(ProjectInvitation invitation, Project project, User inviter, User invitee, CancellationToken cancellationToken = default)

Parameters

invitation ProjectInvitation

The project invitation entity that was accepted.

project Project

The project the invitee joined.

inviter User

The user who sent the invitation.

invitee User

The user who accepted the invitation.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task
Implementation of using SendGrid's dynamic templates for project-related email notifications.

Remarks

Uses the "ProjectInviteAccepted" SendGrid dynamic template (configured via ProjectInviteAcceptedTemplateId).

Exceptions

ArgumentException

Thrown when inviter email is empty, null, or does not match the email regex pattern.

InvalidOperationException

Thrown when SendGrid API key cannot be resolved or SendGrid API returns a non-success status code.

SendProjectInvitationAsync(ProjectInvitation, Project, User, User, string, string, CancellationToken)

Sends a project invitation email to an invitee using SendGrid's dynamic template.

public Task SendProjectInvitationAsync(ProjectInvitation invitation, Project project, User inviter, User invitee, string acceptUrl, string declineUrl, CancellationToken cancellationToken = default)

Parameters

invitation ProjectInvitation

The project invitation entity containing invitation details.

project Project

The project the user is being invited to join.

inviter User

The user who sent the invitation.

invitee User

The user being invited to join the project.

acceptUrl string

The URL for accepting the invitation (typically includes a secure token).

declineUrl string

The URL for declining the invitation (typically includes a secure token).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task
Implementation of using SendGrid's dynamic templates for project-related email notifications.

Remarks

Uses the "ProjectInvite" SendGrid dynamic template (configured via ProjectInviteTemplateId). The template receives dynamic data including project name, inviter name, invitee name, project description, invitation message, accept/decline URLs, and links to view open invitations.

The frontend base URL is determined from the FRONTEND_BASE_URL environment variable, defaulting to "https://www.builvero.com" if not set.

Exceptions

ArgumentException

Thrown when invitee email is empty, null, or does not match the email regex pattern.

InvalidOperationException

Thrown when SendGrid API key cannot be resolved or SendGrid API returns a non-success status code.

SendProjectInvitationDeclinedAsync(ProjectInvitation, Project, User, User, string?, CancellationToken)

Sends a notification email to the inviter when an invitation is declined.

public Task SendProjectInvitationDeclinedAsync(ProjectInvitation invitation, Project project, User inviter, User invitee, string? reason, CancellationToken cancellationToken = default)

Parameters

invitation ProjectInvitation

The project invitation entity that was declined.

project Project

The project the invitee declined to join.

inviter User

The user who sent the invitation.

invitee User

The user who declined the invitation.

reason string

Optional reason provided by the invitee for declining.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task
Implementation of using SendGrid's dynamic templates for project-related email notifications.

Remarks

Uses the "ProjectInviteDeclined" SendGrid dynamic template (configured via ProjectInviteDeclinedTemplateId). If no reason is provided, "No reason provided" is used in the template data.

Exceptions

ArgumentException

Thrown when inviter email is empty, null, or does not match the email regex pattern.

InvalidOperationException

Thrown when SendGrid API key cannot be resolved or SendGrid API returns a non-success status code.

SendProjectJoinApprovedAsync(ProjectJoinRequest, Project, User, User, CancellationToken)

Sends a notification email to the requester when a join request is approved.

public Task SendProjectJoinApprovedAsync(ProjectJoinRequest request, Project project, User requester, User owner, CancellationToken cancellationToken = default)

Parameters

request ProjectJoinRequest

The project join request entity that was approved.

project Project

The project the requester was approved to join.

requester User

The user whose join request was approved.

owner User

The project owner who approved the request.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task
Implementation of using SendGrid's dynamic templates for project-related email notifications.

Remarks

Uses the "ProjectJoinApproved" SendGrid dynamic template (configured via ProjectJoinApprovedTemplateId).

Exceptions

ArgumentException

Thrown when requester email is empty, null, or does not match the email regex pattern.

InvalidOperationException

Thrown when SendGrid API key cannot be resolved or SendGrid API returns a non-success status code.

SendProjectJoinDeclinedAsync(ProjectJoinRequest, Project, User, User, string?, CancellationToken)

Sends a notification email to the requester when a join request is declined.

public Task SendProjectJoinDeclinedAsync(ProjectJoinRequest request, Project project, User requester, User owner, string? reason, CancellationToken cancellationToken = default)

Parameters

request ProjectJoinRequest

The project join request entity that was declined.

project Project

The project the requester was declined from joining.

requester User

The user whose join request was declined.

owner User

The project owner who declined the request.

reason string

Optional reason provided by the owner for declining.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task
Implementation of using SendGrid's dynamic templates for project-related email notifications.

Remarks

Uses the "ProjectJoinDeclined" SendGrid dynamic template (configured via ProjectJoinDeclinedTemplateId). If no reason is provided, "No reason provided" is used in the template data. The template includes a link to discover other projects.

Exceptions

ArgumentException

Thrown when requester email is empty, null, or does not match the email regex pattern.

InvalidOperationException

Thrown when SendGrid API key cannot be resolved or SendGrid API returns a non-success status code.

SendProjectJoinRequestAsync(ProjectJoinRequest, Project, User, User, string, string, CancellationToken)

Sends a project join request email to the project owner using SendGrid's dynamic template.

public Task SendProjectJoinRequestAsync(ProjectJoinRequest request, Project project, User requester, User owner, string approveUrl, string declineUrl, CancellationToken cancellationToken = default)

Parameters

request ProjectJoinRequest

The project join request entity containing request details.

project Project

The project the user is requesting to join.

requester User

The user requesting to join the project.

owner User

The project owner who will receive the notification.

approveUrl string

The URL for approving the join request (typically includes a secure token).

declineUrl string

The URL for declining the join request (typically includes a secure token).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task
Implementation of using SendGrid's dynamic templates for project-related email notifications.

Remarks

Uses the "ProjectJoinRequest" SendGrid dynamic template (configured via ProjectJoinRequestTemplateId). The template receives dynamic data including project name, requester name, owner name, request message, approve/decline URLs, and links to view open requests and discover projects.

Exceptions

ArgumentException

Thrown when owner email is empty, null, or does not match the email regex pattern.

InvalidOperationException

Thrown when:

  • SendGrid API key cannot be resolved
  • ProjectJoinRequestTemplateId is not configured
  • FromEmail is not configured
  • SendGrid API returns a non-success status code