protected void btnSubmit_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(Recaptcha1.Response)) { lblMessage.Text = "Captcha cannot be empty."; } else { var result = Recaptcha1.Verify(); if (result.Success) { Response.Redirect("Welcome.aspx"); } else { lblMessage.Text = "Error(s): "; foreach (var err in result.ErrorCodes) { lblMessage.Text = lblMessage.Text + err; } } } }
protected void InviaButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(Recaptcha1.Response)) { lblMessage.Text = "Inserire codice reCaptcha in basso"; } else { RecaptchaVerificationResult result = Recaptcha1.Verify(); if (result == RecaptchaVerificationResult.Success) { ////Preparo i campi della mail String from = "*****@*****.**"; String to = "*****@*****.**"; //Istanzio la classe che rappresenta il messaggio MailMessage mMailMessage = new MailMessage(); //Aggiungo il Mittente mMailMessage.From = new MailAddress(from); //Aggiungo il destinatario mMailMessage.To.Add(new MailAddress(to)); mMailMessage.To.Add(new MailAddress("*****@*****.**")); //L'oggetto mMailMessage.Subject = "Richiesta informazioni da sito web"; //Il corpo mMailMessage.Body = "Richiesta di informazioni ricevuta tramite il sito www.santuariodicaravaggio.eu<br/><br/><strong>Messaggio inviato da:</strong> " + NomeTextBox.Text + " " + CognomeTextBox.Text + "<br/><strong>Mail:</strong> " + MailTextBox.Text + "<br/><strong>Tel:</strong> " + TelTextBox.Text + "<br/><br/><strong>Testo del messaggio:</strong> <br/>" + RichiestaTtBox1.Text; //Setto la modalità testo, per il contenuto del messaggio. Sarebbe possibile inviare anche dell'HTML mettendo true mMailMessage.IsBodyHtml = true; //Setto la priorità mMailMessage.Priority = MailPriority.Normal; //configurazione nel web.config SmtpClient mSmtpClient = new SmtpClient(); //Invio il messaggio mSmtpClient.Send(mMailMessage); Response.Redirect("FormResponse.aspx"); } if (result == RecaptchaVerificationResult.IncorrectCaptchaSolution) { lblMessage.Text = "reCaptcha inserito in modo scorretto"; } else { lblMessage.Text = "C'è stato un problema, riprova."; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(Recaptcha1.Response)) { lblMessage.Text = "Captcha cannot be empty."; } else { RecaptchaVerificationResult result = Recaptcha1.Verify(); if (result == RecaptchaVerificationResult.Success) { Response.Redirect("Welcome.aspx"); } if (result == RecaptchaVerificationResult.IncorrectCaptchaSolution) { lblMessage.Text = "Incorrect captcha response."; } else { lblMessage.Text = "Some other problem with captcha."; } } }
/// <summary> /// Método para enviar el correo electrónico /// </summary> /// <param name="titulo"></param> /// <param name="nombre"></param> /// <param name="correo"></param> /// <param name="mensaje"></param> private void Enviar(string titulo, string nombre, string correo, string mensaje) { if (String.IsNullOrEmpty(Recaptcha1.Response)) { lblAviso.Text = "El código captcha no puede estar vacío."; } else { RecaptchaVerificationResult result = Recaptcha1.Verify(); if (result == RecaptchaVerificationResult.Success) { string to = ConfigurationManager.AppSettings["To"]; MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress(to)); mail.From = new MailAddress(correo, nombre); mail.Subject = titulo + " " + correo; mail.Body = mensaje + "\n\n" + nombre + "\n" + correo; SmtpClient smtp = new SmtpClient(); smtp.Send(mail); Limpiar(); lblAviso.Text = "Mensaje enviado. Gracias por su tiempo."; } else { if (result == RecaptchaVerificationResult.IncorrectCaptchaSolution) { lblAviso.Text = "El códifo de verificacion es incorrecto."; } else { lblAviso.Text = "Ha ocurrido un error al reconocer el código captcha."; } } } }