Open Closed

How to replace the existing email sender with my own? #260


User avatar
0
alper created
Support Team Director

How can I switch to my custom email sender service, other than the default one.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    You can create a new class inherits from IEmailSender

    public class MyCustomEmailSender : IEmailSender
        {
            public Task SendAsync(string to, string subject, string body, bool isBodyHtml = true)
            {
                throw new System.NotImplementedException();
            }
    
            public Task SendAsync(string @from, string to, string subject, string body, bool isBodyHtml = true)
            {
                throw new System.NotImplementedException();
            }
    
            public Task SendAsync(MailMessage mail, bool normalize = true)
            {
                throw new System.NotImplementedException();
            }
    
            public Task QueueAsync(string to, string subject, string body, bool isBodyHtml = true)
            {
                throw new System.NotImplementedException();
            }
        }
        
    

    alternatively, you can inherit from EmailSenderBase, so you can just override the SendEmailAsync()

        public class MyCustomEmailSender : EmailSenderBase
        {
            public MyCustomEmailSender(IEmailSenderConfiguration configuration, IBackgroundJobManager backgroundJobManager) : base(configuration, backgroundJobManager)
            {
            }
    
            protected override Task SendEmailAsync(MailMessage mail)
            {
               //send your email
            }
        }
    

    And replace the existing implemantation with yours in your Application project's ApplicationModule. Remove the below code section

    #if DEBUG
                context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
    #endif
    

    and add

    context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, MyCustomEmailSender>());
    

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.