I need to send a email to all my subscribers. I am currently on a shared hosting plan that offers a SQL Server 2008 database.
I really don’t want to copy all the emails into my mail client (thunderbird) nor do I want to make a program that would grab all the emails from the db and send it through smtp.net
I am looking for a free solution that I could just tell it the db path and the column of the emails and will allow me to write a subject and body and let me send it.
Depending on whether you want to send the same message to everyone, or personalize each one, you can use a loop to either build up chunks of addresses to BCC (you won’t necessarily want to send to all the recipients at once) or to craft the individualized body/subject for each recipient.
Once you have a body and recipient(s) in each iteration of the loop, you can use msdb.dbo.sp_send_dbmail to send each message.
EDIT adding some sample code.
Setup:
If you want to just send all the same message and assuming the list is short – batching or chunking would be a different question:
— If you want to send an individual message to each recipient, use a cursor:
Cleanup:
Finally, if your list of recipients is large, I’ll suggest you seek other alternatives that are better equipped for bulk mailing.