Contenidos
Crear JSON con nombre, asunto, texto del mensaje y dirección de correo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$alumnos = '{ "alumnos": { "alumno": [ { "id": "1", "Nombre": "Juanito", "Subject": "Asunto del correo", "cuerpo": "Hola mundo", "Correo": "[email protected]" }, { "id": "2", "Nombre": "Pepe", "Subject": "Asunto del correo", "cuerpo": "Hola mundo", "Correo": "[email protected]" } ] } }' | ConvertFrom-Json |
Enviar correo desde powershell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$alumnos.alumnos.alumno | %{ #$_.Nombre, $_.Correo $EmailTo = $_.Correo $Subject = $_.Subject $SMTPServer = "smtp.outlook.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo $message.Subject = $Subject $message.IsBodyHTML = $true $message.Body = $_.cuerpo $pass = Read-Host "introduce contraseña" -AsSecureString $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, $pass) $SMTPClient.Send($message) } |