Share Pastebin
Guest
Public paste!

Mario Cares

By: a guest | Oct 14th, 2009 | Syntax: VB.NET | Size: 2.93 KB | Hits: 157 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. Imports System
  2. Imports System.Collections
  3. Imports System.Net
  4. Imports System.Net.Mail
  5. Imports System.Net.Mime
  6.  
  7. Module Module1
  8.  
  9. Public Sub Conecta()
  10.         Try
  11.             conn.ConnectionString = "Server="TU SERVIDOR";Database="TU BASE DE DATOS";Uid="TU USUARIO";Pwd="TU CONTRASEÑA";"
  12.         Catch ex As Exception
  13.             Dim MensajeMail As String
  14.             MensajeMail = ex.ToString
  15.             No_Base(MensajeMail)
  16.         Finally
  17.             conn.Open()
  18.         End Try
  19.  
  20.     End Sub
  21. '--------------------------------------------------------
  22. Public Sub No_Base(ByVal mensaje As String)
  23.         Dim msg As String
  24.         Dim title As String
  25.         Dim style As MsgBoxStyle
  26.         Dim response As MsgBoxResult
  27.         msg = "Mmmm un error al tratar de conectarme a la Base de Datos..." _
  28.         & vbNewLine & "Mandar mail a Marito?"
  29.         style = MsgBoxStyle.DefaultButton2 Or _
  30.            MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
  31.         title = "Error al Conectar"
  32.  
  33.         response = MsgBox(msg, style, title)
  34.         If response = MsgBoxResult.Yes Then
  35.             Try
  36.                 MandaMail(mensaje)
  37.             Catch ex As Exception
  38.                 MsgBox("El mensaje NO se ha enviado..." & vbNewLine & "Contacte a Marito." _
  39.                        , MsgBoxStyle.Information, "Mensaje NO enviado")
  40.             End Try
  41.         End If
  42.         MsgBox("El programa se cerrará", MsgBoxStyle.Information, "Se cierra")
  43.         End
  44.     End Sub
  45. '-----------------------------------------------------------------------------------
  46. Sub MandaMail(ByVal mensaje As String)
  47.         Dim MMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
  48.         MMessage.To.Add("mario.cares03@alumnos.inacap.cl") 'A quién va destinado el mail
  49.         MMessage.From = New MailAddress("mario.lukose@gmail.com", "Programa Monte Alto", System.Text.Encoding.UTF8) 'Mail, y nombre de quien envia
  50.         MMessage.Subject = "Error :?" 'Asunto
  51.         MMessage.SubjectEncoding = System.Text.Encoding.UTF8
  52.         MMessage.Body = "" & mensaje & "" 'Aquí va el mensaje. Como ven, esta concatenado el "ex". Pueden escribir algo más si quieren xD
  53.         MMessage.BodyEncoding = System.Text.Encoding.UTF8
  54.         MMessage.IsBodyHtml = False
  55.         Dim SClient As New SmtpClient()
  56.         SClient.Credentials = New System.Net.NetworkCredential("mario.lukose@gmail.com", ""& Contraseña xD &"") 'mail y contraseña
  57.         SClient.Host = "smtp.gmail.com" 'smtp de Gmail
  58.         SClient.Port = 587  'Puerto de Gmail
  59.         SClient.EnableSsl = True
  60.         Try
  61.             SClient.Send(MMessage)
  62.             MsgBox("Mensaje enviado correctamente", MsgBoxStyle.Information, "Mensaje Enviado")
  63.         Catch ex As System.Net.Mail.SmtpException
  64.             MsgBox("El mensaje NO se ha enviado..." _
  65.                    & vbNewLine & "Contacte a Marito.", MsgBoxStyle.Information, "Mensaje NO enviado")
  66.         End Try
  67.     End Sub
  68. End Module