PowerShell Script: Mass-Mailer
Today a colleague asked me to write a script to send out a email to a large group of people but have the phrase “Dear <person’s name”>” in the beginning of email body.
I quickly wrote this script. Here are the steps you need to take before executing it:
1. Zip and place the Mass-Mailer folder somewhere on your computer. There are 3 files in the folder:
2. in Mass-Mailer.ps1 file, modify the highlighted section ( and remove the “<” and “>”brackets):
3. Open recipientsList.txt and enter recipients name and emails, one recipient per line with format Name;Email (i.e. John Smith;John.Smith@xxx.com)
4. Write the email in EmailBody.txt
5. Execute Mass-Mailer.PS1
The email is sent to each recipient individually. it looks like:
2 Comments
Thanks, this is almost what I am looking for. I have to send email to approx 5000 people with an attachment.
My question is:
1) how to add an attachment
2) what is this error
New-Object : Exception calling “.ctor” with “2″ argument(s): “The parameter ‘address’ cannot be an empty string.
Parameter name: address”
At \\server\home$\user\Mass-Mailer\Mass-Mailer.PS1:44 char:28
+ $objRecipient = New-Object <<<< System.Net.Mail.MailAddress($strEmail, $strName)
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Exception calling "Add" with "1" argument(s): "Value cannot be null.
Parameter name: item"
At \\server\home$\user\Mass-Mailer\Mass-Mailer.PS1:48 char:21
+ $MailMessage.To.add <<<< ($objRecipient)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "Send" with "1" argument(s): "A recipient must be specified."
At \\server\home$\user\Mass-Mailer\Mass-Mailer.PS1:50 char:18
+ $SMTPClient.Send <<<< ($MailMessage)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Remove-Variable : Cannot find a variable with name 'objRecipient'.
At \\server\home$\user\Mass-Mailer\Mass-Mailer.PS1:51 char:17
+ Remove-Variable <<<< objRecipient
+ CategoryInfo : ObjectNotFound: (objRecipient:String) [Remove-Variable], ItemNotFoundException
+ FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand
How does your recipientsList.txt look like?