Created
July 3, 2018 18:38
-
-
Save BipulRaman/84deb87b1977d0751ffafbded1626652 to your computer and use it in GitHub Desktop.
www.bipul.in | Bulk Email from Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Script for bulk emailing by getting data from CSV | |
Author: Bipul Raman | |
#> | |
$MailingList = Import-Csv E:\MailingList.csv | |
#SMTP Server and port may differ for different email service provider | |
$SMTPServer = "smtp.gmail.com" | |
$SMTPPort = "587" | |
#Your email id and password | |
$Username = "email@gmail.com" | |
$Password = "Password" | |
#Iterating data from CSV mailing list and sending email to each person | |
foreach ( $person in $MailingList) | |
{ | |
$iName = $person.Name | |
$iEmail = $person.Email | |
$iAddress = $person.Address | |
$to = $person.Email | |
$cc = "other@domain.com" | |
$subject = "Email Subject" | |
$body = @" | |
Hi $iName, | |
Your address is : $iAddress | |
Regards, | |
Your Name | |
"@ | |
$attachment = "C:\test.txt" | |
$message = New-Object System.Net.Mail.MailMessage | |
$message.subject = $subject | |
$message.body = $body | |
$message.to.add($to) | |
$message.cc.add($cc) | |
$message.from = $username | |
$message.attachments.add($attachment) | |
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort); | |
$smtp.EnableSSL = $true | |
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password); | |
$smtp.send($message) | |
Write-Host Mail Sent to $iName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment