diff --git a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs index 287e7b36e..39f53cb54 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs @@ -271,7 +271,17 @@ public class EmailLogService(IRepository _emailLogRepository, [HttpPost] public async Task SynchronizationEmail(SynchronizationEmailInDto inDto) { - var maxTime = await _emailLogRepository.MaxAsync(t => t.EmailDate); + + var fromEmail = _systemEmailConfig.FromEmail; + + + if (inDto.TrialId != null) + { + fromEmail= await _trialRepository.Where(x => x.Id == inDto.TrialId.Value).Select(x => x.EmailFromEmail).FirstNotNullAsync(); + + } + + var maxTime = await _emailLogRepository.Where(x=>x.SenderAddress== fromEmail).MaxAsync(t => t.EmailDate); var startDate = maxTime ?? DateTime.MinValue; List emailList = new List(); List EmailRecipientLogList = new List();