We have a system that send emails through an automated system to warn users. The system first collects all the emails that have to be sent out. Then it goes through a loop and send out the emails. In this loop there is an error handling. This error handling includes inserting the email, which email and the error message into a table in our database when it couldn't be send. The error number is -2147220977 and the description is 'the server rejected one or more recipient addresses.The server response was: 550'.
When the system comes at an email that couldn't be send (due to it doesn't exist) it will keep on trying to send the email untill the connection timeout is expired (60 seconds). This error also reflects to the rest of the emails that has to be sent out that comes after the wrong email in the loop. These correct emails are also inserted in a table in the database but the recipients recieves them.
How can we avoid that when the system comes at a wrong email it doesn't try to send it more than ones? So if it is a wrong email it just inserts it into the table and doesn't try to send it again.
set rsApprover = objConn.Execute(mysqlstatement)
if not rsApprover.eof then
'select email to be sent to performer in next flow (Brand Director)
set rsMailBody = objConn.Execute("SELECT * FROM tblMailTemplates WHERE ([MailTemplate-ID] = 72)")
do while not rsApprover.eof
error = 0
set rsEmployees = objConn.execute(sqlstatementemail)
'send to Brand Director
Set ObjMail = CreateObject("CDO.Message")
Set ObjMailCon = CreateObject("CDO.Configuration")
'Out going SMTP server
ObjMailCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = application("smtpserver")
ObjMailCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = application("smtpserverport")
ObjMailCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = application("sendusing")
ObjMailCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = application("smtpconnectiontimeout")
'Update the CDOSYS Configuration
Set ObjMail.Configuration = ObjMailCon
ObjMail.From = firstname.lastname@example.org
ObjMail.To = rsEmployees("Email")
ObjMail.Subject = rsMailBody("SubjectEN")
strBody = rsMailBody("BodyEN")
ObjMail.TextBody = strBody
Set ObjMail = Nothing
'check for error and create emailbody
if Err.number <> 0 then
error = 1
strBody = strBody & "<tr>"
strBody = strBody & "<td>2</td>"
strBody = strBody & "<td></td>"
strBody = strBody & "<td>" & rsApprover("PerformerStudent-ID") & "</td>"
strBody = strBody & "<td>" & rsEmployees("Lastname") & "</td>"
strBody = strBody & "<td>" & rsEmployees("Firstname") & "</td>"
strBody = strBody & "<td>" & rsEmployees("Email") & "</td>"
strBody = strBody & "<td>" & rsEmployees("Name") & "</td>"
strBody = strBody & "</tr>"
'function to trap the error
if (error = 1) then
set rsUpdate = objConn.Execute("INSERT INTO tblMailNotSend (...)" &_
set rsUpdate = objConn.Execute("INSERT INTO tblMailSend (...)" &_
'send email to admin if invitation(s) couldn't be send