lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
https://lukelowrey.com/dotnet-email-guide-2021/
MIT License
3.04k stars 438 forks source link

Can't change the sender just before sending the email #323

Open Abdelrahmandev1984 opened 2 years ago

Abdelrahmandev1984 commented 2 years ago

As the sender has limited emails per day or per hour, I need to select the proper sender according to the number of receivers, I am using Mailkit sender and trying to do something like that but still send from the default sender configured in DI

fluentEmail.Sender = GetFluentEmailSender(fluentEmail.Sender, fluentEmail.Data.ToAddresses.Count);

The DI configuration:

services.AddFluentEmail(defaultFromEmail, defaultFromName).
                AddRazorRenderer(templateRootFolder);

services.AddSingleton<ISender>(new MailKitSender(
                new SmtpClientOptions
                {
                    Server = notificationSettings.EmailSettings.MailKitSender.Server,
                    Port = notificationSettings.EmailSettings.MailKitSender.Port,
                    Password = password,
                    UseSsl = notificationSettings.EmailSettings.MailKitSender.UseSsl,
                    User = notificationSettings.EmailSettings.MailKitSender.UserName,
                    SocketOptions = (MailKit.Security.SecureSocketOptions)notificationSettings.EmailSettings.MailKitSender.SocketOptions,
                    RequiresAuthentication = notificationSettings.EmailSettings.MailKitSender.RequiresAuthentication
                }

                ));

Is this a bug or am I misusing it?