public async Task SendEmail(EnvioEmailViewModel model) { try { Util util = new Util(); var configuracaoEmail = await _repositoryConfiguracaoEmail.GetById(1);
byte[] file = ConvertIFormFileToByteArray(model.Anexo);
util.EnviarEmailComAnexo(configuracaoEmail.Remetente, configuracaoEmail.Smtp, configuracaoEmail.Porta, configuracaoEmail.Senha, model.Email, corpoEmail, file);
return model;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public byte[] ConvertIFormFileToByteArray(IFormFile file) { if (file == null || file.Length == 0) { return null; }
using (var memoryStream = new MemoryStream())
{
file.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}