using Nop.Core; using Nop.Core.Domain.Messages; using Nop.Core.Infrastructure; using Nop.Services.Media; using Nop.Services.Messages; namespace Nop.Plugin.Misc.Brevo.Services; /// /// Represents overridden email sender /// public class BrevoEmailSender : EmailSender { #region Fields protected readonly BrevoSettings _brevoSettings; protected readonly IStoreContext _storeContext; #endregion #region Ctor public BrevoEmailSender(BrevoSettings brevoSettings, IDownloadService downloadService, INopFileProvider fileProvider, ISmtpBuilder smtpBuilder, IStoreContext storeContext ) : base(downloadService, fileProvider, smtpBuilder) { _brevoSettings = brevoSettings; _storeContext = storeContext; } #endregion #region Methods /// /// Sends an email /// /// Email account to use /// Subject /// Body /// From address /// From display name /// To address /// To display name /// ReplyTo address /// ReplyTo display name /// BCC addresses list /// CC addresses list /// Attachment file path /// Attachment file name. If specified, then this file name will be sent to a recipient. Otherwise, "AttachmentFilePath" name will be used. /// Attachment download ID (another attachedment) /// Headers /// A task that represents the asynchronous operation public override async Task SendEmailAsync(EmailAccount emailAccount, string subject, string body, string fromAddress, string fromName, string toAddress, string toName, string replyTo = null, string replyToName = null, IEnumerable bcc = null, IEnumerable cc = null, string attachmentFilePath = null, string attachmentFileName = null, int attachedDownloadId = 0, IDictionary headers = null) { //add store identifier in email headers if (emailAccount.Id == _brevoSettings.EmailAccountId) { var store = await _storeContext.GetCurrentStoreAsync(); headers ??= new Dictionary(); headers.Add(BrevoDefaults.EmailCustomHeader, store.Id.ToString()); } await base.SendEmailAsync(emailAccount, subject, body, fromAddress, fromName, toAddress, toName, replyTo, replyToName, bcc, cc, attachmentFilePath, attachmentFileName, attachedDownloadId, headers); } #endregion }