lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.

Home Page:https://lukelowrey.com/dotnet-email-guide-2021/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't change the sender just before sending the email

Abdelrahmandev1984 opened this issue · comments

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?