public void EnviaEmails() { var emails = RetornaEmails(false); emails.ToList().ForEach(a => { try { UtilitarioBusiness.EnviaEmail(UtilitarioBusiness.RetornaChaveConfig("nomeRemetente"), UtilitarioBusiness.RetornaChaveConfig("emailRemetente"), a.Destinatario, a.Assunto, a.Corpo); a.DataEnvio = DateTime.Now; a.DataAlteracao = DateTime.Now; SalvaEmail(a); } catch (Exception ex) { IncluiErroBusiness(MensagemBusiness.RetornaMensagens("Email_ErroEnvio", new string[] { a.Id.ToString(), UtilitarioBusiness.RetornaExceptionMessages(ex) }), true); } }); if (!IsValid()) { StringBuilder texto = new StringBuilder(); serviceResult.Messages.ForEach(a => texto.AppendLine(a.Message)); UtilitarioBusiness.GravaArquivoTexto(UtilitarioBusiness.RetornaChaveConfig("caminhoArquivoEmailLogErro") + "\\" + string.Format(UtilitarioBusiness.RetornaChaveConfig("nomeArquivoEmailLogErro"), DateTime.Now.ToString("yyyMMddHHmmss")), false, texto.ToString()); } }
protected void GeraErro(HttpStatusCode statusCode, Exception ex) { ServiceResult serviceResult = new ServiceResult(); serviceResult.Success = false; serviceResult.Messages.Add(new ServiceResultMessage() { Message = UtilitarioBusiness.RetornaExceptionMessages(ex) }); var json = JsonConvert.SerializeObject(serviceResult); HttpResponseMessage response = this.Request.CreateErrorResponse(statusCode, json); throw new HttpResponseException(response); }