Email SMTP sending limit (thinks it is spam)

Topics: Help
May 17, 2008 at 10:06 PM
Edited May 17, 2008 at 10:10 PM

I'm running Club Starter Kit "v2 RC1" and my SMTP server must have just enacted a limit of how may email addresses can be in the "To:" line before it thinks the email is spam.  Below is the VB code that the site uses to send emails.  Does anyone know the fastest way to revise this code to make it work.  Maybe send the email in groups of 10 recipients or send them one at a time for everyone in the group selected.  Any tips are greatly appreciated.  I just need to be able to get emails out!

 

   
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
        'Ensure that at least one role has been selected.
        Dim recipientChecked As Boolean = False
        For Each item As ListItem In chkRecipients.Items
            If item.Selected Then
                recipientChecked = True
                Exit For
            End If
        Next

        If recipientChecked = False Then
            If chkAllMembers.Checked = False Then
                'No recipients were selected.  We can exit the sub.
                lblError.Text = "No recipients selected."
                lblError.Visible = True
                Return
            End If
        Else
            lblError.Text = ""
            lblError.Visible = False
        End If

        'Check to see if someone missed clicking Upload.  If this is the case, AttachmentFile upload control will have a file.
        If String.IsNullOrEmpty(AttachmentFile.FileName) OrElse AttachmentFile.PostedFile Is Nothing Then
        Else
            fileUpload_Click(Me, System.EventArgs.Empty)
        End If

        Dim haveAttachment As Boolean = False
        Dim strFiles() As String = Nothing

        If txtAttachments.Text.Length > 0 Then
            strFiles = Split(txtAttachments.Text, ControlChars.NewLine)
            haveAttachment = True
        End If

        Dim ToAddresses As MailAddressCollection = GetRecipients()

        Dim mem As MembershipUser = Membership.GetUser()
        Dim gui As New Guid(mem.ProviderUserKey.ToString)
        Dim name As String = GetName(gui)
        Dim msgFrom As New MailAddress(mem.Email.ToString(), name.ToString())
        Dim msgMail As New MailMessage(msgFrom, msgFrom)

        For Each msgTo As MailAddress In ToAddresses
            msgMail.Bcc.Add(msgTo)
        Next

        msgMail.Subject = txtSubject.Text

        msgMail.IsBodyHtml = True
        msgMail.Body = FCKeditor1.Value

        If haveAttachment Then
            Dim str As String
            For Each str In strFiles
                If str = "" Then Continue For
                msgMail.Attachments.Add(New Attachment(strPath & str))
            Next
        End If
        Dim smtp As New SmtpClient(ConfigurationManager.AppSettings("ClubMailServer").ToString())
        Dim a As New Net.NetworkCredential(ConfigurationManager.AppSettings("ClubMailUsername").ToString(), ConfigurationManager.AppSettings("ClubMailPassword").ToString())
        smtp.UseDefaultCredentials = False
        smtp.Credentials = a
        smtp.Send(msgMail)
        Response.Redirect("~/default.aspx")

    End Sub

 

 

 

 

 

May 19, 2008 at 12:04 AM
Edited May 19, 2008 at 12:05 AM

I figured it out.  It is as simple as moving the "Next" statement down and adding a clear statement before  msgMail.Bcc.Add(msgTo)

        For Each msgTo As MailAddress In ToAddresses
            msgMail.To.Clear() 'clears the "To:" variable for the next email address.  VERY IMPORTANT!
            msgMail.To.Add(msgTo)
            ''Next  'Comment out old next function...
            'The next was moved down so emails would send through mail.kendaleoaks.com one at a time.

            msgMail.Subject = txtSubject.Text

            msgMail.IsBodyHtml = True
            msgMail.Body = FCKeditor1.Value

            If haveAttachment Then
                Dim str As String
                For Each str In strFiles
                    If str = "" Then Continue For
                    msgMail.Attachments.Add(New Attachment(strPath & str))
                Next
            End If
            Dim smtp As New SmtpClient(ConfigurationManager.AppSettings("ClubMailServer").ToString())
            Dim a As New Net.NetworkCredential(ConfigurationManager.AppSettings("ClubMailUsername").ToString(), ConfigurationManager.AppSettings("ClubMailPassword").ToString())
            smtp.UseDefaultCredentials = False
            smtp.Credentials = a
            smtp.Send(msgMail)
        Next 'new next statement locaion so the code sends one email at a time to members.
        Response.Redirect("~/default.aspx")