Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BipulRaman/84deb87b1977d0751ffafbded1626652 to your computer and use it in GitHub Desktop.
Save BipulRaman/84deb87b1977d0751ffafbded1626652 to your computer and use it in GitHub Desktop.
www.bipul.in | Bulk Email from Powershell
<#
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