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
apiKeyResolverISendGridApiKeyResolverService for resolving SendGrid API key from various sources.
optionsIOptions<SendGridOptions>SendGrid configuration options including template IDs and sender information.
loggerILogger<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
apiKeyResolverISendGridApiKeyResolverService for resolving SendGrid API key from various sources.
optionsIOptions<SendGridOptions>SendGrid configuration options including template IDs and sender information.
loggerILogger<ProjectNotificationEmailSender>Logger for recording email operations and errors.
clientFactoryFunc<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
invitationProjectInvitationThe project invitation entity that was accepted.
projectProjectThe project the invitee joined.
inviterUserThe user who sent the invitation.
inviteeUserThe user who accepted the invitation.
cancellationTokenCancellationTokenCancellation 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
invitationProjectInvitationThe project invitation entity containing invitation details.
projectProjectThe project the user is being invited to join.
inviterUserThe user who sent the invitation.
inviteeUserThe user being invited to join the project.
acceptUrlstringThe URL for accepting the invitation (typically includes a secure token).
declineUrlstringThe URL for declining the invitation (typically includes a secure token).
cancellationTokenCancellationTokenCancellation 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
invitationProjectInvitationThe project invitation entity that was declined.
projectProjectThe project the invitee declined to join.
inviterUserThe user who sent the invitation.
inviteeUserThe user who declined the invitation.
reasonstringOptional reason provided by the invitee for declining.
cancellationTokenCancellationTokenCancellation 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
requestProjectJoinRequestThe project join request entity that was approved.
projectProjectThe project the requester was approved to join.
requesterUserThe user whose join request was approved.
ownerUserThe project owner who approved the request.
cancellationTokenCancellationTokenCancellation 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
requestProjectJoinRequestThe project join request entity that was declined.
projectProjectThe project the requester was declined from joining.
requesterUserThe user whose join request was declined.
ownerUserThe project owner who declined the request.
reasonstringOptional reason provided by the owner for declining.
cancellationTokenCancellationTokenCancellation 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
requestProjectJoinRequestThe project join request entity containing request details.
projectProjectThe project the user is requesting to join.
requesterUserThe user requesting to join the project.
ownerUserThe project owner who will receive the notification.
approveUrlstringThe URL for approving the join request (typically includes a secure token).
declineUrlstringThe URL for declining the join request (typically includes a secure token).
cancellationTokenCancellationTokenCancellation 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