daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 410 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [string]$to = "marcelo@eth1.com.br"
  2. [String]$from = "marcelo@eth1.com.br"
  3. [String]$subject = "TESTE POWERSHELL"
  4. [String[]]$users = "mvldebian@gmail.com"
  5. [String]$smtpserver = "smtp.office365.com"
  6. [string]$office365User = 'marcelo@eth1.com.br';
  7. [string]$office365Password = 'minha senha';
  8. [String]$port = 587
  9.  
  10. foreach ($user in $users)
  11. {
  12.     trap
  13.     {
  14.         #$CRLF added because usual `r`n in string doesnot work within trap.
  15.         [string]$CRLF = [char]13 + [char]10
  16.         $script:errorMessage += '"' + $smtpserver + '" : Error: {0}' -f $_.Exception.Message + $CRLF;
  17.         $Error.Clear();
  18.         continue;
  19.     }
  20.     $to      = $user
  21.     $output = "<pre>" + "<font color='#800000'>scriptErrors: `r`n" + $script:errorMessage + "</font>`r`n"
  22.     $output += "<b>" + $outputHeader + "</b><font color='#800000'>" + $outputAlert + "</font>" + "<b>" + $outputSubHeader + "</b>" + $outputAll + "</pre>"
  23.  
  24.     # Create mail message
  25.     $message = New-Object system.net.mail.MailMessage
  26.     $message.From = $from;
  27.     foreach ($useremail in $to)
  28.     {
  29.         $message.To.Add($useremail);
  30.     }
  31.     $message.Subject = $subject;
  32.     $message.Body = $output;
  33.     $message.IsBodyHtml = $true;
  34.     #Create SMTP client
  35.     $client = New-Object system.Net.Mail.SmtpClient $smtpserver, $port
  36.     $client.EnableSsl = $true
  37.     # Credentials are necessary if the server requires the client # to authenticate before it will send e-mail on the client's behalf.
  38.     #$client.Credentials = [system.Net.CredentialCache]::DefaultNetworkCredentials
  39.     $client.Credentials = New-Object System.Net.NetworkCredential( $office365User , $office365Password );
  40.      
  41.     # Try to send the message
  42.     $client.Send($message)
  43.     # reset variables
  44.     $body = ""
  45.     $message.Dispose()
  46.     $client.Dispose()
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top