Advertisement
Guest User

Untitled

a guest
Feb 7th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. let apariencia2 = SCLAlertView.SCLAppearance(
  2. showCloseButton: false
  3. )
  4. alertView = SCLAlertView(appearance: apariencia2).showWait("Espere", subTitle: "Enviando Correo...")
  5.  
  6. // Move to a background thread to do some long running work
  7. DispatchQueue.global(qos: .userInitiated).async {
  8.  
  9. let smtpSession = MCOSMTPSession()
  10. smtpSession.hostname = "smtp.gmail.com"
  11. smtpSession.username = "unimo2016@gmail.com"
  12. smtpSession.password = "Emo100510ew5"
  13. smtpSession.port = 465
  14. smtpSession.authType = MCOAuthType.saslPlain
  15. smtpSession.connectionType = MCOConnectionType.TLS
  16. smtpSession.connectionLogger = {(connectionID, type, data) in
  17. if data != nil {
  18. if let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){
  19. NSLog("Connectionlogger: \(string)")
  20. }
  21. }
  22. }
  23.  
  24. let builder = MCOMessageBuilder()
  25. builder.header.to = [MCOAddress(displayName: self.textoNombre.text!, mailbox: "info@modelo.edu.mx")]
  26. builder.header.from = MCOAddress(displayName: "Escuela Modelo", mailbox: self.textoCorreo.text!)
  27. builder.header.subject = self.textoAsunto.text!
  28. builder.htmlBody = "Nombre: " + self.textoNombre.text! + "\n" + "Correo: " + self.textoCorreo.text! + "\n" + "Teléfono: " + self.textoTelefono.text! + "\n" + "Mensaje: " + self.textoMensaje.text!
  29.  
  30. let rfc822Data = builder.data()
  31. let sendOperation = smtpSession.sendOperation(with: rfc822Data)
  32. sendOperation?.start { (error) -> Void in
  33. DispatchQueue.main.async {
  34.  
  35. if (error != nil) {
  36. //DETIENE EL TIEMPO DE ESPERA
  37. self.alertView?.close()
  38. //MENSAJE
  39. let alerta = UIAlertController(title: "Error",
  40. message: "Falló el envío de tu mensaje",
  41. preferredStyle: UIAlertControllerStyle.alert)
  42. let accion = UIAlertAction(title: "Cerrar",
  43. style: UIAlertActionStyle.default) { _ in
  44. alerta.dismiss(animated: true, completion: nil) }
  45. alerta.addAction(accion)
  46. self.present(alerta, animated: true, completion: nil)
  47. //JLToast.makeText(NSLocalizedString("Falló el envío de tu mensaje",comment:"Datos Actualizados"), duration: 1).show()
  48. NSLog("Error al mandar mensaje: \(String(describing: error))")
  49. } else {
  50. //DETIENE EL TIEMPO DE ESPERA
  51. self.alertView?.close()
  52. //MENSAJE
  53. let alerta = UIAlertController(title: "",
  54. message: "Tu Mensaje se ha enviado",
  55. preferredStyle: UIAlertControllerStyle.alert)
  56. let accion = UIAlertAction(title: "Cerrar",
  57. style: UIAlertActionStyle.default) {
  58. _ in
  59. self.borrarCampos()
  60. self.view.endEditing(true)
  61.  
  62. }
  63. alerta.addAction(accion)
  64. self.present(alerta, animated: true, completion: nil)
  65.  
  66. //JLToast.makeText(NSLocalizedString("Tu correo se ha enviado",comment:"Datos Actualizados"), duration: 1).show()
  67. NSLog("Mensaje enviado")
  68. }
  69. }
  70.  
  71. }
  72. //dispatch
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement