Question : Sending multiple emails

I want to send a number of emails using ASP. The email addresses are held in a mySQL table.
I would like to send the first email direct ,with BCCs to the remaining ones in the table (or rather generated by a query of the table).
My present coding just sends emails without BCCs:

Dim Mail
Dim objCDOSYSCon , objCDOSYSMail, BodyString, ResponseString, myRS, db, strSQL, strSQL2
Dim mySQLWhere, MonthString, Connection, FullLoginName, Prompt, UserID, myCmd, myCmd2, RecordID, EmailTextID
Dim EmailText, strFinalMsg, NumberSent, NumberNotSent, strHeader, BodyText, NumberRemaining
EmailTextID = CCGetParam("ID", Empty)
strSQL="ID = " & EmailTextID




Set Connection = New clsDBConnection1
Connection.Open
UserID = Connection.ToSQL(CCGetUserID(), ccsInteger)
EmailText = CCDLookup("fldtext", "tblemailtext", strSQL, Connection)
FullLoginName = CCDLookup("fldFullName", "tblpasswords", "fldID = " & UserID , Connection)

'response.Write EmailText
'response.end

'This prevents the form from being Cached.
Response.Expires = 0
Response.Expiresabsolute = Now-1

'Create the MailSender Object
Set Mail = Server.CreateObject("Persits.MailSender")
Set myCmd = Server.CreateObject("ADODB.Command")
Set myCmd2 = Server.CreateObject("ADODB.Command")
Set myRS = Server.CreateObject("ADODB.Recordset")

'Specify your SMTP Mail Server
Mail.Host = "mailA28.webcontrolcenter.com"

'Specify the From Address and Name
Mail.From = "[email protected]"
'Mail.From = "matthewo'gorman@lifecharity.org.uk"
'Mail.FromName = FullLoginName
Mail.FromName = "Matthew O'Gorman, LIFE London"
Mail.Subject = "LIFE talks"

strHeader = " " & _
""
'EmailText & ""

'Mail.Body = strFinalMsg



'Specify of the message is plain text or HTML
Mail.IsHTML = True


strSQL = "SELECT tblselectedschools.fldContact AS CONTACT, tblschools.fldNAME AS SCHOOLNAME, tblschools.fldTOWN AS SCHOOLTOWN, tblselectedschools.fldSalutation AS SALUTATION, tblselectedschools.fldemail, tblselectedschools.fldRecordID FROM tblschools RIGHT JOIN tblselectedschools ON tblschools.fldSCHOOL_ID = tblselectedschools.fldSCHOOL_ID WHERE tblselectedschools.fldUserID = " & UserID & _
" AND tblselectedschools.fldSelected = 1 AND TRIM(tblselectedschools.fldemail) <>''"
'response.Write strSQL
'response.end

Set myRS = Connection.Execute(strSQL)

NumberSent = 0
NumberNotSent = 0

Do While Not myRS.EOF

RecordID = myRS.Fields("fldRecordID")
'Mail.AddRecipient myRS.Fields("fldContact"), myRS.Fields("fldemail")
'BodyText = strHeader & myRS.Fields("CONTACT") & "
" & myRS.Fields("SCHOOLNAME") & "
" & myRS.Fields("SCHOOLTOWN") & _
BodyText = "

" & myRS.Fields("SALUTATION") & "

" & EmailText & ""

Mail.Body = BodyText
Mail.AddAddress myRS.Fields("fldemail"), FullLoginName
'Try to send the message
Mail.Send


'If there is an error, print it out, if the message sends ok, show success!
If Err <> 0 Then ' error occurred
    'response.write("Message Error: " & Err.Description)
   NumberSent=NumberNotSent+1
   Emails.txtEmailsNotSent.Value= NumberSent

else
   'Label1.Value="Email sent to: " & myRS.Fields("fldemail")
   'Label1.Value = " " & Label1.Value & ""
   NumberSent=NumberSent+1
   Emails.txtEmailsSent.Value= NumberSent
 'response.write("Your Message has been sent!")
End If



myRS.MoveNext()
Loop

strSQL = "DELETE FROM tblselectedschools WHERE tblselectedschools.fldUserID = " & UserID & _
" AND tblselectedschools.fldSelected = 1 AND TRIM(tblselectedschools.fldemail) <>''"
Connection.Execute strSQL
strSQL = "SELECT COUNT(*) AS REMAINING FROM tblselectedschools WHERE tblselectedschools.fldUserID = " & UserID & _
" AND tblselectedschools.fldSelected = 1"
Set myRS=Connection.Execute(strSQL)
NumberRemaining=myRS("REMAINING")

Connection.Close
Set Connection = Nothing
On Error Goto 0

'response.Write NumberRemaining
'response.end
If CInt(NumberRemaining)>0 Then
response.Redirect "SchoolsMailMerge.asp"
Else
response.Redirect "Home.asp"
End If


How can I adapt this so that each recipient only sees their own email address

Answer : Sending multiple emails

The problem is that you are navigating to an ASP page, and it is going ahead and trying to send batches of emails. The entire send process must be done while your browser hangs waiting for a reply from the server. Your script will most likely time out before it finishes working.

You could have the page send out maybe ten emails, then return. Keep track in your database somewhere which ones have been sent and which ones haven't. Each time you run the page have it send out ten more emails. Then, just have the page output some meta tags at the end to make the page automatically reload after a few seconds, e.g.



The proper way to do this, however, would be to not use an ASP page at all. Make a scheduled task or cron job on your server, which would run a script that sends out the emails. Then the server would execute the task itself, at some particular time, without you browsing to the page. However to do this, your web host needs to have exposed those kinds of options to you. If they haven't, and you don't own the server (e.g. you can't log into it or remote desktop in), you won't be able to set this up.

Perhaps you should instead be looking into a third party mass mailing service?
Random Solutions  
 
programming4us programming4us