-1
Guys, I need your help. Each form that is registered in my system it sends in e-mail to some people warning that it has been registered, except that I have two environments, one of homologation and one of production. I need that when I send an email, it signals the place that was registered
public void NovoEventoAdverso(int patientId, int hospitalId, int usuarioId)
{
var cadastroRepository = new CadastroRepository();
var investigadorRepository = new UsuarioRepository();
var randomizacaoRepository = new RandomizacaoRepository();
var paciente = cadastroRepository.GetByPatientId(patientId, hospitalId);
var investigador = investigadorRepository.GetbyId(usuarioId);
var randomizacao = randomizacaoRepository.GetByPatientId(patientId, hospitalId);
MailMessage objEmail = FactoryMailMessage();
objEmail.To.Add("Nome Teste <[email protected]>");
objEmail.Subject = $"Novo Evento Adverso - {paciente.inpac}";
var conteudo = "Novo Evento Adverso cadastrado:<br />";
conteudo += $"Iniciais do Paciente: {paciente.inpac}<br />";
conteudo += $"Nome do Investigador: {investigador.Nome}<br />";
conteudo += $"Data da Randomização: {randomizacao.RandomizacaoData.Value.ToString("dd/MM/yyyy")}<br />";
conteudo += $"Data do Preenchimento: {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}";
objEmail.Body = conteudo;
EnviarEmail(objEmail);
}
private static void EnviarEmail(MailMessage objEmail)
{
var objSmtp = new SmtpClient
{
Host = "smtp.mandrillapp.com",
EnableSsl = true,
Port = 587
};
const string user = "####@#####.com.br";
const string senha = "######";
objSmtp.Credentials = new NetworkCredential(user, senha);
objSmtp.Send(objEmail);
}
In another deleted comment you said something like going through connectionstring, I didn’t understand what you were thinking
– Gabriel Coletta
@Gabrielcoletta type, do some checking pulling on connectionstring, because I have 2 environments, I have 2 connectionstring in the system, then in this case, check which one is being used, or check the url understand? i have an example here that checks Pea URL, but I’m not able to adapt it to use in my Mailservice. --- var isHomolog = Request.url.Absoluteuri.Contains("Homolog") || Request.url.Absoluteuri.Contains("localhost") ? true : false;
– Leonardo Macedo
What I can recommend to you is to tag the web.config saying if it is development or production, in the case of the system Deploy it would change the web.config correctly.
– Gabriel Coletta
Can you give me an example?
– Leonardo Macedo