Note that there are some explanatory texts on larger screens.

plurals
  1. POSending email with threaded process
    primarykey
    data
    text
    <p>We have an admin system as the back end for multiple websites, and part of this admin system is an email system that allows emails to be sent to users, either individually or as bulk emails.</p> <p>I've recently re-written the email code to be more robust and correctly log email status and any errors that occur.</p> <p>We've successfully tested the email code repeatedly (probably around 20 times) sending to a tad under 2000 users, and it all works fine until I try and run the email send routine in a background thread.</p> <p>I've tried two different threading methods, both adding the thread to the thread pool using </p> <pre><code>Threading.ThreadPool.QueueUserWorkItem(AddressOf SendEmails, emailThread) </code></pre> <p>and creating a new thread using</p> <pre><code>Dim t As New Threading.Thread(New Threading.ParameterizedThreadStart(AddressOf SendEmails)) t.Start(emailThread) </code></pre> <p>(Note: I've only just started working with threading for this project, so if I'm missing something obvious, please point it out)</p> <p>Sometimes, all emails will send fine, and other times, the email code stops after either 600 or 900 emails. It's always 600 or 900, which is the first thing that confuses the hell out of me.</p> <p>For testing purposes, I'm sending to 1841 users, and the email routine takes around 75 minutes to complete.</p> <p>I've written thread pausing into the email routine, as we start to experience rejected recipient failures after around 600 messages, probably due to some anti-spam setting on the mail server, but pausing for 10 minutes then continuing solves this.</p> <p>So, does anyone have any idea why the email sending would seem to stop working after sending exactly 600 or 900 emails? No error is generated, it just stops running the code.</p> <p><strong>EDIT</strong></p> <p>As requested, code for the SendEmail function:</p> <pre><code>Private Sub SendEmails(ByVal vars As EmailThreading) Try For Each user As OD.RegisteredUser In Users Dim email As New OD.Email(vars.Site.SiteID) If String.IsNullOrEmpty(vars.Site.CommunicationBCCAddress) Then email.BCCAddress = Me.txtEmailBCC.Text Else email.BCCAddress = String.Format("{0};{1}", Me.txtEmailBCC.Text, vars.Site.CommunicationBCCAddress) End If ' basically, if there're items in the drop down list, then one ' of them will have been used, so we grab the details from there If Me.ddlReplyFrom.Items.Count &gt; 0 Then email.From = fromAddresses.Item(Me.ddlReplyFrom.SelectedValue) Else email.From = fromAddresses.Item(0) End If email.Body = txtEmailText.Text If Not vars.Comment Is Nothing AndAlso vars.Comment.CommentID &gt; 0 Then email.Body += String.Format("&lt;br /&gt;-------------------------------------------------------&lt;br /&gt;&lt;br /&gt;This message was sent in response to:&lt;br /&gt;&lt;br /&gt;{0}&lt;br /&gt;&lt;br /&gt;Sent: {1}", _comment.Comment, _comment.DateAdded) End If email.Subject = Me.txtEmailSubject.Text email.CCAddress = txtEmailCC.Text email.ToAddress = user.EmailAddress email.EmailRecipientID = user.UserID email.AddAttachments(EmailAttachments) If vars.GroupEmail Then email.GroupEmail = True email.GroupEmailID = vars.GroupEmailID End If email.ContactType = _contactType email.UserType = user.RegisteredUserType email.Send() For Each ODFile As OD.File In vars.Files ODFile.SaveForEmail(email.EmailID) ODFile.SaveForContactLog(email.ContactLogID) Next Next Catch ex As Exception ErrorLog.LogError(ex.Message, "Email send routine", ex.ToString(), OD_Site.SiteID) End Try End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload