So, I've been going through a variety of different ideas to try to send email newsletters, and have run into blockages at about every turn.
I am using a shared hosting environment at the moment, and need it to be stable in this environment.
I had wanted to create a timed, scheduled system that sent batches as a background service, built I cannot do that with this environment, so I am now doing it simply with a long-timeout AJAX post to a .NET form function.
I have a common function which sends emails, and am looping through my database doing that as follows
For Each email In list
If Common.isValidEmail(email("email")) Then
Try
Common.sendEmail(email("email"), Common.tCase(email("email")), content, subject, "true", "newsletter", "customer")
Catch ex As Exception
errorList += email("id") & ","
End Try
Else
Common.changeData("DELETE FROM mailingList WHERE id='" & email("id") & "'")
End If
Next
I am catching two potential error cases here, the isValidEmail
function checks if the email is proper, and then I try send a mail, if that fails, I am then building up an error list.
However, this is no good if the service is interrupted.
So, I am considering modifying it by adding a "sent" flag to to the database row for each email address, but this requires writing to the database for every single loop, will this desperately slow it down?
Then any time it drops out, I can go back to the database and resend to users which have not been flagged.
Does anyone have any better ideas?!
Long term, I want this to be a background service, and am looking into migrating this to Azure, where hopefully I can run scheduled background services, but for now, I need a workaround with a shared environment.