I am trying to send e-mail to candidates that applied for the job, sometimes I have few hundreds or even thousand mails to send, so code would be a help.
This is the one I wrote, but the problem is that mail is sent multiple times on same address (on some addresses once or twice and sometimes even more).
A bit of explanation for the code below. Code reads active job database and picks candidates that haven't been contaced (column FMZ in database, "X"), then reads candidate unique ID in another database for the e-mail address that mail is going to be sent. Even basic msgbox below SmtpServer.Send(mail)
is activated for each candidate only once, but mail is sent multiple times.
Here's the code.
'Step 1 - All candidates in DBAP that applied for ClientID/Job ID
For i As Integer = 0 To dsPoslovi.Tables(0).Rows.Count - 1
If dsPoslovi.Tables(0).Rows(i)(1).ToString() = ATS_IDKlijent AndAlso dsPoslovi.Tables(0).Rows(i)(2).ToString() = ATS_IDPosao Then
'Step 2 - Send mails to those not contacted yet (X in FMZ column)
If dsPoslovi.Tables(0).Rows(i)(8).ToString() <> "X" Then
IDKandidataAP = dsPoslovi.Tables(0).Rows(i)(0).ToString()
IDKandidataAP2 = dsPoslovi.Tables(0).Rows(i)(3).ToString()
'Read mail addresses
For x As Integer = 0 To dsCL.Tables(0).Rows.Count - 1
If dsPoslovi.Tables(0).Rows(i)(3).ToString() = dsCL.Tables(0).Rows(x)(1).ToString() Then
MailKandidata = dsCL.Tables(0).Rows(x)(7).ToString()
If MailKandidata.Contains("@") = True Then
SmtpServer.Send(mail)
MsgBox(MailKandidata)
End If
End If
Next
'Update active job database
Dim cmd As New OleDbCommand(query, myCONN)
myCONN.Open()
cmd.Parameters.AddWithValue("FMZ", "X")
cmd.Parameters.AddWithValue("ID", IDKandidataAP)
cmd.ExecuteNonQuery()
myCONN.Close()
End If
End If
Next