Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let apariencia2 = SCLAlertView.SCLAppearance(
- showCloseButton: false
- )
- alertView = SCLAlertView(appearance: apariencia2).showWait("Espere", subTitle: "Enviando Correo...")
- // Move to a background thread to do some long running work
- DispatchQueue.global(qos: .userInitiated).async {
- let smtpSession = MCOSMTPSession()
- smtpSession.hostname = "smtp.gmail.com"
- smtpSession.username = "unimo2016@gmail.com"
- smtpSession.password = "Emo100510ew5"
- smtpSession.port = 465
- smtpSession.authType = MCOAuthType.saslPlain
- smtpSession.connectionType = MCOConnectionType.TLS
- smtpSession.connectionLogger = {(connectionID, type, data) in
- if data != nil {
- if let string = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){
- NSLog("Connectionlogger: \(string)")
- }
- }
- }
- let builder = MCOMessageBuilder()
- builder.header.to = [MCOAddress(displayName: self.textoNombre.text!, mailbox: "info@modelo.edu.mx")]
- builder.header.from = MCOAddress(displayName: "Escuela Modelo", mailbox: self.textoCorreo.text!)
- builder.header.subject = self.textoAsunto.text!
- builder.htmlBody = "Nombre: " + self.textoNombre.text! + "\n" + "Correo: " + self.textoCorreo.text! + "\n" + "Teléfono: " + self.textoTelefono.text! + "\n" + "Mensaje: " + self.textoMensaje.text!
- let rfc822Data = builder.data()
- let sendOperation = smtpSession.sendOperation(with: rfc822Data)
- sendOperation?.start { (error) -> Void in
- DispatchQueue.main.async {
- if (error != nil) {
- //DETIENE EL TIEMPO DE ESPERA
- self.alertView?.close()
- //MENSAJE
- let alerta = UIAlertController(title: "Error",
- message: "Falló el envío de tu mensaje",
- preferredStyle: UIAlertControllerStyle.alert)
- let accion = UIAlertAction(title: "Cerrar",
- style: UIAlertActionStyle.default) { _ in
- alerta.dismiss(animated: true, completion: nil) }
- alerta.addAction(accion)
- self.present(alerta, animated: true, completion: nil)
- //JLToast.makeText(NSLocalizedString("Falló el envío de tu mensaje",comment:"Datos Actualizados"), duration: 1).show()
- NSLog("Error al mandar mensaje: \(String(describing: error))")
- } else {
- //DETIENE EL TIEMPO DE ESPERA
- self.alertView?.close()
- //MENSAJE
- let alerta = UIAlertController(title: "",
- message: "Tu Mensaje se ha enviado",
- preferredStyle: UIAlertControllerStyle.alert)
- let accion = UIAlertAction(title: "Cerrar",
- style: UIAlertActionStyle.default) {
- _ in
- self.borrarCampos()
- self.view.endEditing(true)
- }
- alerta.addAction(accion)
- self.present(alerta, animated: true, completion: nil)
- //JLToast.makeText(NSLocalizedString("Tu correo se ha enviado",comment:"Datos Actualizados"), duration: 1).show()
- NSLog("Mensaje enviado")
- }
- }
- }
- //dispatch
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement