0

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.

Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97

1 Answers1

0

Yes, you will increase the reliability of your solution drastically by adding a status to your database records which can tell you if the individual records have been processed as part of this batch yet. This way, you can setup a process that calls your function every once in a while and you send only X number of messages per each call. Thus, if your host is throttling how many emails you can send per hour, you will now be able to easily control that by tweaking how many get sent on each call and how often you are executing your function.

You probably do not need to be concerned about the speed of updating every record as you process it, as sending an SMTP message is typically slower than updating a local database. If your database is that slow where it is making a difference, then the machine you are running it on is probably too shy on resources (i.e. need more ram) ot time for a new faster machine.

dmarietta
  • 1,940
  • 3
  • 25
  • 32