Advertisement
Guest User

Untitled

a guest
Dec 29th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. [HttpPost]
  2. public ActionResult Index(string login)
  3. {
  4. try
  5. {
  6. var tbuscar = new UsuarioAplicacao();
  7. var retorno = tbuscar.ListarPorLogin(login);
  8.  
  9. if (retorno != null)
  10. {
  11. string infLogin = retorno.login;
  12. string infSenha = retorno.senha;
  13. string infNome = retorno.nomeusuario;
  14. int infId = retorno.idusuario;
  15.  
  16. string texto = "O seu login é : " + infLogin + " é sua senha é : " + infSenha;
  17.  
  18. MailMessage mail = new MailMessage();
  19.  
  20. mail.From = new MailAddress("itasouza1@gmail.com"); //de
  21. mail.To.Add(infLogin); // para
  22. mail.Subject = "Recuperação de senha"; // assunto
  23. mail.Body = "Segue informações sobre usuário e senha: n" + texto; // mensagem
  24.  
  25.  
  26. using (var smtp = new SmtpClient("smtp.gmail.com"))
  27. {
  28. smtp.EnableSsl = true; // GMail requer SSL
  29. smtp.Port = 587; // porta para SSL
  30. smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // modo de envio
  31. smtp.UseDefaultCredentials = false; // vamos utilizar credencias especificas
  32.  
  33. // seu usuário e senha para autenticação
  34. smtp.Credentials = new NetworkCredential("itasouza1@gmail.com", "******");
  35.  
  36. // envia o e-mail
  37. smtp.Send(mail);
  38. }
  39.  
  40.  
  41. TempData["msg"] = "E-mail enviado com sucesso";
  42.  
  43. }
  44. else
  45. {
  46. TempData["Erro"] = "Usuário não cadastrado.";
  47. }
  48.  
  49. ModelState.Clear();
  50. }
  51. catch (Exception ex)
  52. {
  53. TempData["Erro"] = ex.Message;
  54. }
  55.  
  56. return View();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement