public async Task SendAsync(int userId, string from, ICollection <string> to, ICollection <string> cc, ICollection <string> bcc, string subject, string textHtmlBody, ICollection <IFormFile> attachments = null) { var emailAccountWithSmtpSettings = await _emailAccountRepository.GetByUserIdAndByEmailWithSmtpAsync(userId, from, false); if (emailAccountWithSmtpSettings == null || emailAccountWithSmtpSettings.Smtp == null) { throw new Exception("Email account with this ids does not exist."); } var sendedEmailMessage = new SendedEmailMessage(from, to, subject, textHtmlBody, emailAccountWithSmtpSettings); ICollection <SendedAtachment> sendedAttachments = null; if (attachments != null && attachments.Count > 0) { sendedAttachments = await ConvertFormFilesToSendedAttachments(attachments); sendedEmailMessage.AddSendedAtachments(sendedAttachments); } await _emailClientFactory.SendAsync(emailAccountWithSmtpSettings.Email, emailAccountWithSmtpSettings.Password, emailAccountWithSmtpSettings.Smtp.Host, emailAccountWithSmtpSettings.Smtp.Port, emailAccountWithSmtpSettings.User.Name, to, cc, bcc, subject, textHtmlBody, sendedAttachments); await _sendedEmailMessageRepository.AddAsync(sendedEmailMessage); }