Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/powershellpower.com/public_html/page_parts/page.php on line 78

Warning: Use of undefined constant page_id - assumed 'page_id' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 92

Warning: Use of undefined constant synopsis - assumed 'synopsis' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 93

How to send large batches of emails

There are many occasions when you need to send out a lot of emails in a short amount of time, using a list of email eddresses we can process these in powershell and quickly send a customised email to a large list within seconds

4
Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/powershellpower.com/public_html/page_parts/page.php on line 156

Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Import recipient addresses

First we need to import our list of email addresses. In my example I have made a small csv with a few email addresses and names. We can use the name and any other values we like later to customise the email to the recipient.


$addresses = import-csv C:\Users\reelfunky\Desktop\email.csv



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Create a foreach loop

Next we will create a foreach loop to process each entry within the email list, within the loop we are creating the variables to use in the email text and the email command at the end of the loop


foreach ($address in $addresses){
$thisaddress=$address.email_address
$thisname = $address.name}



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Create the message

Now we create the message, we can use variables to customise the email to the user, I am just using the recipient's name in this example but you can use make use of as many variables as you require


$messagebody ="Hi $thisname, I am just testing my bulk email tool, regards, Ricky"



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Send the message

Finally, we take all the variables we have processed and put them into the send-mailmessage command. The foreach loop in my tests takes just a few milliseconds to process each cycle. If you do not have an smtp server there are ways to make use of googles or Microsoft etc


send-mailmessage -to $thisaddress -from test@powershellpower.com -Subject "Test Emails" -SmtpServer 'smtp.powershellpower.com' -Body $messagebody



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
The full script

$addresses = import-csv C:\Users\reelfunky\Desktop\email.csv
foreach ($address in $addresses){
$thisaddress=$address.email_address
$thisname = $address.name}
$messagebody ="Hi $thisname, I am just testing my bulk email tool, regards, Ricky"
send-mailmessage -to $thisaddress -from test@powershellpower.com -Subject "Test Emails" -SmtpServer 'smtp.powershellpower.com' -Body $messagebody


Cut & Paste


Comments

Notice: Undefined variable: commentno in /var/www/powershellpower.com/public_html/page_parts/page.php on line 335
// Collect comments ''
Fatal error: Uncaught Error: Call to a member function fetch_assoc() on bool in /var/www/powershellpower.com/public_html/page_parts/comments.php:9 Stack trace: #0 /var/www/powershellpower.com/public_html/page_parts/page.php(343): include() #1 /var/www/powershellpower.com/public_html/pages/how_to_send_large_batches_of_emails.php(2): include('/var/www/powers...') #2 {main} thrown in /var/www/powershellpower.com/public_html/page_parts/comments.php on line 9