Advertisement
abhi_madhani

Windows Email Script (Using Power Shell)

Nov 14th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This script will send an E-mail.
  2. # Send the script -to, -subject parameter followed by -body parameter.
  3.  
  4. $filename = "C:\Path\to\file\name.txt"
  5. $smtpserver = "smtp.gmail.com"
  6. $msg = new-object Net.Mail.MailMessage
  7. # $att = new-object Net.Mail.Attachment($filename)
  8. $smtp = new-object Net.Mail.SmtpClient($smtpServer )
  9. $smtp.EnableSsl = $True
  10. $smtp.Credentials = New-Object System.Net.NetworkCredential("username", "password"); # Put username without the @GMAIL.com or – @gmail.com
  11. $msg.From = "[email protected]"
  12. $msg.To.Add("[email protected]")
  13. $msg.Subject = "Email Subjetc"
  14. $msg.Body = (Get-Content $filename ) -join "<BR>"
  15. $msg.IsBodyHTML = $true
  16. # $msg.Attachments.Add($att)
  17. $smtp.Send($msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement