Skip to content

[feature] EmailChannelSender allow for send from email#4826

Open
MarshallRJ wants to merge 1 commit intoshesha-io:releases/0.43from
MarshallRJ:feature-emailChannelSenderAllowFroceFromAddress
Open

[feature] EmailChannelSender allow for send from email#4826
MarshallRJ wants to merge 1 commit intoshesha-io:releases/0.43from
MarshallRJ:feature-emailChannelSenderAllowFroceFromAddress

Conversation

@MarshallRJ
Copy link
Copy Markdown

@MarshallRJ MarshallRJ commented Apr 17, 2026

We are using Sendgrid as our smtp email sender. There is no way to force the emails to have the defaultFromAddress forced to be set as what is configured in the SMTP settings. If smtpRelay is set we use the defaultFromAddress and if not we use the configured smtp username (This was the functioning in the obsolete SheshaEmailSender)

We have added this feature

Summary by CodeRabbit

  • New Features
    • Added a new SMTP configuration option to force outgoing emails to use the configured sender address, overriding any caller-provided "from" addresses.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

Walkthrough

The PR adds a ForceFromAddressFromSettings boolean property to SMTP configuration models and updates email sending logic to respect this flag. When enabled, the configured SMTP settings override any caller-supplied "from" address, with behavior determined by relay configuration.

Changes

Cohort / File(s) Summary
Configuration Models
shesha-core/src/Shesha.Framework/Configuration/Email/SmtpSettings.cs, shesha-core/src/Shesha.Application/Email/Dtos/SmtpSettingsDto.cs
Added new boolean property ForceFromAddressFromSettings to both the domain model and its corresponding DTO to control forced override of email "from" addresses.
Service Layer
shesha-core/src/Shesha.Application/Email/EmailSenderAppService.cs
Updated UpdateSmtpSettingsAsync to persist the new ForceFromAddressFromSettings field and GetSmtpSettingsAsync to include it in returned DTO.
Email Sending Logic
shesha-core/src/Shesha.Application/Notifications/Emails/EmailChannelSender.cs
Modified BuildMessageWith to conditionally override "from" address when property is true or input is null/empty, with behavior based on UseSmtpRelay setting and DefaultFromAddress availability.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant EmailSender as EmailChannelSender
    participant Settings as SmtpSettings

    Client->>EmailSender: BuildMessageWith(fromAddress, smtpSettings)
    EmailSender->>Settings: Check ForceFromAddressFromSettings
    
    alt fromAddress is null/empty OR ForceFromAddressFromSettings is true
        Settings->>EmailSender: ForceFromAddressFromSettings = true
        alt UseSmtpRelay enabled
            Settings->>EmailSender: DefaultFromAddress + DisplayName
            EmailSender->>EmailSender: Set From with DefaultFromAddress
        else UseSmtpRelay disabled
            Settings->>EmailSender: UserName
            EmailSender->>EmailSender: Set From with UserName
        end
    else fromAddress provided AND ForceFromAddressFromSettings is false
        EmailSender->>EmailSender: Set From with provided fromAddress
    end
    
    EmailSender->>Client: Return configured MailMessage
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A fluffy config hops along,
With FromAddress, bold and strong,
Force the sender, override the call,
No more disputes—one rule for all!
SMTP relay now stands tall,
Whisker-tested, bounce-free and all!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title references 'allow for send from email' which partially relates to the changes, but the phrasing is incomplete/awkward and obscures the main feature: forcing emails to use the configured SMTP default address. Clarify the title to better convey the primary feature. Consider: 'Allow forcing emails to use configured SMTP default address' or 'Add ForceFromAddressFromSettings configuration option'.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@shesha-core/src/Shesha.Application/Notifications/Emails/EmailChannelSender.cs`:
- Around line 143-161: When ForceFromAddressFromSettings is true,
EmailChannelSender must always use smtpSettings.DefaultFromAddress as the
message.From regardless of smtpSettings.UseSmtpRelay; update the block in
EmailChannelSender so it selects DefaultFromAddress unconditionally when
ForceFromAddressFromSettings==true and throw a clear InvalidOperationException
if DefaultFromAddress is null/empty (do not fall back to smtpSettings.UserName).
Also ensure you do not construct a MailAddress from UserName in this forced
branch. Finally, review SheshaEmailSender.NormalizeMailSender to either honor
ForceFromAddressFromSettings the same way or document that the flag applies only
to EmailChannelSender and adjust behavior accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ff0685fe-d001-48e3-8467-c5de38e4937b

📥 Commits

Reviewing files that changed from the base of the PR and between afe1356 and 8802be8.

📒 Files selected for processing (4)
  • shesha-core/src/Shesha.Application/Email/Dtos/SmtpSettingsDto.cs
  • shesha-core/src/Shesha.Application/Email/EmailSenderAppService.cs
  • shesha-core/src/Shesha.Application/Notifications/Emails/EmailChannelSender.cs
  • shesha-core/src/Shesha.Framework/Configuration/Email/SmtpSettings.cs

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