Advertisement
Guest User

Untitled

a guest
Mar 6th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. $MailingList = Import-Csv E:\MailingList.csv
  2.  
  3. #SMTP Server and port may differ for different email service provider
  4. $SMTPServer = "smtp.gmail.com"
  5. $SMTPPort = "587"
  6.  
  7. #Your email id and password
  8. $Username = "email@gmail.com"
  9. $Password = "Password"
  10.  
  11. #Iterating data from CSV mailing list and sending email to each person
  12. foreach ( $person in $MailingList)
  13. {
  14. $iName = $person.Name
  15. $iEmail = $person.Email
  16. $iAddress = $person.Address
  17.  
  18. $to = $person.Email
  19. $cc = "other@domain.com"
  20. $subject = "Email Subject"
  21. $body = @"
  22.  
  23. Hi $iName,
  24.  
  25. Your address is : $iAddress
  26.  
  27. Regards,
  28. Your Name
  29.  
  30. "@
  31. $attachment = "C:\test.txt"
  32.  
  33. $message = New-Object System.Net.Mail.MailMessage
  34. $message.subject = $subject
  35. $message.body = $body
  36. $message.to.add($to)
  37. $message.cc.add($cc)
  38. $message.from = $username
  39. #$message.attachments.add($attachment)
  40.  
  41. $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
  42. $smtp.EnableSSL = $true
  43. $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
  44. $smtp.send($message)
  45. Write-Host Mail Sent to $iName
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement