Función para Enviar correo

Function Enviar-Correo
{
 #region intro_funcion
  #descripcion: Enviar correo con formato HTML de un objeto de PS
  #fecha creac: xx/xx/11
  #versión    : 0.3 (31/10/13)
  #autor      : Jorge Mestre
  #Changelog  : xx/xx/11 - creado
  #Changelog  : 05/08/13 - Corregido formato y agrupado en una sola funcion.
  #Changelog  : 31/10/13 - Parametrizacion
 #endregion intro_funcion
 [CmdletBinding(PositionalBinding=$false)]
 param(
 [Parameter(Mandatory=$true)]$cuerpo,
 [switch]$cuerpoHTML,
 [switch]$attach,
 $asunto     = 'Prueba envío',
 $cabecera   = "Primera linea en el cuerpo del correo",
 $de         = "prueba@labo.local",
 $para       = ("dest1@labo.local","destN@labo.local"),
 $SMTPserver = "hostname_server_SMTP"
 )
 
 #Formato tabla HTML
 [string]$fhtml = "<style>"
 $fhtml = $fhtml + "TABLE{font-family:Arial,Helvetica,sans-serif;`
          border-spacing:1px;border-width: 1px;border-style: solid;`
          border-color: black;border-collapse: collapse;}"
 $fhtml = $fhtml + "TH{white-space: nowrap;border-spacing:1px;font-size:10pt;`
          border-width: 1px;padding: 3px;border-style: solid;border-color: black;`
          background-color:#E0ECFF}"
 $fhtml = $fhtml + "TD{white-space: nowrap;border-spacing:1px;font-size:10pt;`
          border-width: 1px;padding: 3px;border-style: solid;border-color: black;}"
 $fhtml = $fhtml + "</style>"
  
 #si es un Array, convertirlo en HTML
 if (-not $cuerpoHTML)
 {
  $infoExtra = try{InfoExtraScriptCorreo}catch {""}
  [string]$cuerpo = $cuerpo | convertto-html -Head $fhtml
  $cuerpo = '<p>'+$cabecera+'</p>'+$cuerpo+$infoExtra
 }
 
 if ($attach)
 { 
  Send-MailMessage -To $para -Subject $asunto -SmtpServer $SMTPserver -From $de `
  -Body $cuerpo -Bodyashtml:$true  -Encoding ([System.Text.Encoding]::UTF8) `
  -Attachments $attach 
 }
 else
 {
  Send-MailMessage -To $para -Subject $asunto -SmtpServer $SMTPserver `
  -From $de -Body $cuerpo -Bodyashtml:$true  ` 
  -Encoding ([System.Text.Encoding]::UTF8)
 }
} # Function Enviar-Correo


 
PS >; $unArray = Get-Command | select name,Module -last 10
PS >; Enviar-Correo -cuerpo $unArray


No hay comentarios.: