Create a new project, try to use oauth for the email sender, theres no native support. Override the EmailSender or the EmailSenderBase to add oauth, this is successful if you want to always send from same mailbox, with same credentials. If you want tenants to be able to configure their own oauth on their tenant (for example to send email notifications to their users using their own domain) its not possible in current UI.
2 Answer(s)
-
0
- ABP’s built-in Emailing settings UI (Setting Management → Emailing) is designed for SMTP settings. There is no native tenant-level OAuth2 UI for the email sender in ABP 10.0.
- The recommended/working approach is to make email sending tenant-aware by:
- Storing OAuth configuration per tenant (via Setting Management or your own entity),
- Replacing
IEmailSenderwith your own implementation that reads the current tenant’s configuration and sends using OAuth (e.g., Microsoft Graph, Gmail API, or SMTP with OAuth2 via MailKit if that’s your provider).
1) Store per-tenant OAuth settings (Setting Management)
Define your own setting names and register them with a
SettingDefinitionProvider. ABP settings are automatically resolved per-tenant.public static class TenantEmailOAuthSettings { private const string Prefix = "MyApp.Email.OAuth"; public const string Provider = Prefix + ".Provider"; // e.g. "MicrosoftGraph", "Gmail" public const string TenantId = Prefix + ".TenantId"; public const string ClientId = Prefix + ".ClientId"; public const string ClientSecret = Prefix + ".ClientSecret"; public const string FromAddress = Prefix + ".FromAddress"; public const string FromDisplayName = Prefix + ".FromDisplayName"; }Then, create a custom settings UI page (Blazor Server) similar to how custom setting pages are added (same technique as “white labeling” examples: define settings + implement an app service using
ISettingManager+ add a UI page/group).2) Replace
IEmailSenderwith a tenant-aware OAuth senderImplement
IEmailSenderand read settings usingISettingProvider(which resolves values in the context of the current tenant).using System.Net.Mail; using Volo.Abp.DependencyInjection; using Volo.Abp.Emailing; using Volo.Abp.Settings; public class TenantOAuthEmailSender : IEmailSender, ITransientDependency { private readonly ISettingProvider _settingProvider; public TenantOAuthEmailSender(ISettingProvider settingProvider) { _settingProvider = settingProvider; } public async Task SendAsync(MailMessage mail, bool normalize = true) { // Read per-tenant OAuth configuration var provider = await _settingProvider.GetOrNullAsync(TenantEmailOAuthSettings.Provider); var clientId = await _settingProvider.GetOrNullAsync(TenantEmailOAuthSettings.ClientId); var clientSecret = await _settingProvider.GetOrNullAsync(TenantEmailOAuthSettings.ClientSecret); // Use these to send via your chosen OAuth provider (Graph/Gmail/etc.) // (Implementation depends on provider; this is where you call Graph API, etc.) throw new NotImplementedException(); } public Task SendAsync(string to, string subject, string body, bool isBodyHtml = true) => SendAsync(new MailMessage { Subject = subject, Body = body, IsBodyHtml = isBodyHtml, To = { to } }); public Task SendAsync(string from, string to, string subject, string body, bool isBodyHtml = true) => SendAsync(new MailMessage(from, to, subject, body) { IsBodyHtml = isBodyHtml }); public Task QueueAsync(string to, string subject, string body, bool isBodyHtml = true) => SendAsync(to, subject, body, isBodyHtml); // or integrate with background jobs }Register it by replacing ABP’s default email sender:
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Modularity; public class MyAppEmailModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.Replace(ServiceDescriptor.Transient<IEmailSender, TenantOAuthEmailSender>()); } }3) Make the settings editable by tenants (ABP UI / SaaS)
If you want tenants to edit email-related settings themselves, ABP can gate this via tenant features (SaaS). In practice, you enable the relevant tenant feature in the SaaS tenant management screen (this is how built-in “Emailing” settings visibility is controlled).
4) If you need “OAuth + SMTP” specifically
ABP’s default UI won’t cover OAuth flows. You typically:
- Create your own page to capture client id/secret/tenant id and perform admin consent / token acquisition (provider-specific),
- Persist the resulting tokens/credentials per tenant,
- Use them in your
IEmailSenderimplementation.
Sources (verified)
- https://abp.io/docs/latest/framework/infrastructure/emailing
- https://abp.io/support/questions/10065
- https://abp.io/support/questions/7579
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
hi
You can add some settings for your new OAuth email sender.
Then add the UI page to allow the host and tenant to change it.
Try to retrieve the settings for the current tenant in your OauthEmailSender. You can now use host and tenant OAuth values.
https://github.com/abpframework/abp/blob/dev/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/TenantSettingManagerExtensions.cs
https://abp.io/docs/latest/modules/setting-management#mvc-ui
Thanks.