Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Custom IEmailSender implementation not being invoked #3813


User avatar
0
blewis created

I will be deploying my project to Azure, which doesn't support SMTP. I have created a new EmailSenderSendGrid class that implements IEmailSender but uses the SendGrid API.

I then added:

IocManager.Register<IEmailSender, EmailSenderSendGrid>();

to the PostInitialize() method of my ProjectNameCoreModule.cs (in the Core project) in an attempt to register the new implementation. However, when I attempt to send an email from an MVC controller, it throws and exception and that exception is coming from Abp.MailKit.MailKitEmailSender. So that implies it's still trying to use MailKit and not my class. What am I doing wrong?

This is the first time I am trying to use the IocManager to register my own implementation...so perhaps I am screwing that up.

Thanks, Bryan


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @blewis,

    Can you try to replace IEmailSender implementation like this in PreInitialize of your module.

    Configuration.ReplaceService<IEmailSender, EmailSenderSendGrid>(DependencyLifeStyle..Transient);
    
  • User Avatar
    0
    blewis created

    Thanks. This worked!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)