Guest User

Send File

a guest
Jul 25th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Connection Details
  2. $username=”xxxx”
  3. $password=”xxxx”
  4. $smtpServer = “smtp-relay.gmail.com”
  5. $msg = new-object Net.Mail.MailMessage
  6.  
  7. #Change port number for SSL to 587
  8. $smtp = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  9.  
  10. #Uncomment Next line for SSL  
  11. $smtp.EnableSsl = $true
  12.  
  13. $smtp.Credentials = New-Object System.Net.NetworkCredential( $username, $password )
  14.  
  15. #From Address
  16. $msg.From = "xxxx"
  17. #To Address, Copy the below line for multiple recipients
  18. $msg.To.Add(“xxxx”)
  19. $msg.To.Add(“xxxx”)
  20.  
  21. #Message Body
  22. $msg.Body=”Please See Attached Files”
  23.  
  24. #Message Subject
  25. $msg.Subject = “Email with Multiple Attachments”
  26.  
  27. #your file location
  28. $files=Get-ChildItem “C:\xxxx\xxxx”
  29.  
  30. Foreach($file in $files)
  31. {
  32. Write-Host “Attaching File :-$file
  33. $attachment = New-Object System.Net.Mail.Attachment –ArgumentList C:\xxxx\xxxxx\$file
  34. $msg.Attachments.Add($attachment)
  35.  
  36. }
  37. $smtp.Send($msg)
  38. $attachment.Dispose();
  39. $msg.Dispose();
  40.  
  41. Remove-Item "C:\xxxx\xxxx\*.*"
Add Comment
Please, Sign In to add comment