Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Send Emails in Bulk using PowerShell

December 17, 2022
in Blog, Powershell
1
ADVERTISEMENT

Table of Contents

In some cases, we need to email to numerous people from person to person. PowerShell script can be an easier solution for you.

Send Emails in Bulk using PowerShell

Below is the sample PowerShell Script to send bulk emails. It is fetching data from CSV file (represented in below screenshot). This script will send individual email to every single person listed in CSV.

You need to create a CSV file featuring the fields as required.

How to Send Emails in Bulk using PowerShell
$Cred = (Get-Credential)
Import-Csv -Path "C:\Contacts.csv" | 
ForEach-Object {
    $Name = $_.Name
    $Att = $_.Path
    Send-MailMessage `
        -To $_.Email `
        -From "[email protected]" `
        -Subject "This is a message from PowerShell" `
        -Body "Hello $Name!" `
        -Attachments $Att `
        -Credential $Cred `
        -SmtpServer "smtp.office365.com" `
        -Port 587 `
        -UseSsl
Write-Host "Email sent to" $_.Email
}

The output:

PS C:\Windows\system32> Import-Csv -Path "C:\Contacts.csv" |
>> ForEach-Object {
>>     $Name = $_.Name
>>     $Att = $_.Path
>>     Send-MailMessage `
>>         -To $_.Email `
>>         -From "[email protected]" `
>>         -Subject "This is a message from PowerShell" `
>>         -Body "Hello $Name!" `
>>         -Attachments $Att `
>>         -Credential $Cred `
>>         -SmtpServer "smtp.office365.com" `
>>         -Port 587 `
>>         -UseSsl
>> Write-Host "Email sent to" $_.Email
>> }
Email sent to [email protected]
Email sent to [email protected]
Email sent to [email protected]
Email sent to [email protected]
Email sent to [email protected]

As you can see, emails are delivered automatically.

How to Send Emails in Bulk using PowerShell

Another script to sending emails in bulk using System.Net.Mail API.

<#Script for bulk emailing by getting data from CSV#>

$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 protected]"
$Password = "Password"

#Iterating data from CSV mailing list and sending email to each person
foreach ( $person in $MailingList)
{
    $iName = $person.Name
    $iEmail =  $person.Email    
    $iPassword = $person.Password

    $to = $person.Email
    $cc = "[email protected]"
    $subject = "Email Subject"
    $body = @" 
Hi $iName,
Your password is  : $iPassword
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
}
ADVERTISEMENT
5/5 - (2 votes)
Previous Post

PowerShell to Send Emails with Delivery Notification Enabled

Next Post

The SMTP Server Requires a Secure Connection, or the Client was not Authenticated

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Comments 1

  1. Prakash says:
    1 year ago

    How to add the HTML for Email Body

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory