Guest User

Untitled

a guest
Jun 6th, 2018
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #Clear Screen
  2. cls Write-Host "Sending Email"
  3.  
  4. #Creacion del Objeto del Correo
  5. $msg = new-object Net.Mail.MailMessage
  6. $msg.IsBodyHtml = $True
  7.  
  8. #Estructura del Correo
  9. $smtpServer = "smtp.mail.yahoo.com"
  10. $msg.From = "jrosh.01@yahoo.com"
  11. $msg.To.Add("jrsanchez@marzam.com.mx")
  12. $msg.subject = "Notificacion de: $($env:computername)"
  13.  
  14. #Evento del Servicio
  15. $msg.Body =@()
  16. $msg.Body += Get-WinEvent –FilterHashTable @{logname="Microsoft-Windows-
  17. TerminalServices-RemoteConnectionManager/Operational"} -MaxEvents 1 |
  18. ConvertTo-Html -Property Message,TimeCreated,MachineName,Id,LogName -
  19. PreContent "<H1>Inicio de Sesion</H1>" -PostContent "<H5><i>$(get-date)</i>
  20. </H5>" -CssUri C:ScripCss.txt
  21.  
  22. #Creacion del Objeto SMTP
  23. $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  24. $smtp.EnableSsl = 1
  25. $smtp.Port = 587
  26. $cred = New-Object Net.NetworkCredential("jrosh.01@yahoo.com","Rosh1981**")
  27. $smtp.Credentials = $cred
  28.  
  29. #Envia Correo
  30. $smtp.Send($msg)
  31. Write-Host "Correo Enviado..."
  32.  
  33. body { background-color:#E5E4E2;
  34. font-family:Monospace;
  35. font-size:10pt; }
  36. td, th { border:0px solid black;
  37. border-collapse:collapse;
  38. white-space:pre; }
  39. th { color:white;
  40. background-color:black; }
  41. table, tr, td, th { padding: 0px; margin: 0px ;white-space:pre; }
  42. table { margin-left:25px; }
  43. h2 {
  44. font-family:Tahoma;
  45. color:#6D7B8D;
  46. }
  47. .footer
  48. { color:green;
  49. margin-left:25px;
  50. font-family:Tahoma;
  51. font-size:8pt;
  52. }
  53.  
  54. $emailSmtpServer = "smtp.mail.yahoo.com"
  55. $emailSmtpServerPort = "587"
  56. $emailSmtpUser = "jrosh.01@yahoo.com"
  57. $emailSmtpPass = "Rosh1981**"
  58.  
  59. $emailMessage = New-Object System.Net.Mail.MailMessage
  60. $emailMessage.From = "ROSH <jrosh.01@yahoo.com>"
  61. $emailMessage.To.Add( "jrsanchez@marzam.com.mx" )
  62. $emailMessage."Notificacion de: $($env:computername)"
  63. $emailMessage.IsBodyHtml = $true
  64. $emailMessage.Body = @"
  65. <H1>Inicio de Sesion RDP</H1>
  66. <p>Evento a revisar en: <strong>$($evento.MachineName)</strong>.</p>
  67. <p>Identificador: <strong>$($evento.Id)</strong>.</p>
  68. <p>Fecha / Hora: <strong>$($evento.TimeCreated)</strong>.</p>
  69. <p>Texto: <strong>$($evento.Message)</strong>.</p>
  70. <br>
  71. "<H5><i>$(get-date)</i></H5>"
  72. "@
  73.  
  74. $SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer ,
  75. $emailSmtpServerPort )
  76. $SMTPClient.EnableSsl = $true
  77. $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(
  78. $emailSmtpUser , $emailSmtpPass );
  79.  
  80. $SMTPClient.Send( $emailMessage )
  81.  
  82. $emailMessage = Get-WinEvent –FilterHashTable @{logname="Microsoft-Windows-
  83. TerminalServices-RemoteConnectionManager/Operational"} -MaxEvents 1
Add Comment
Please, Sign In to add comment