Why am I receiving two identical emails instead of one?
// Email Sending event
public bool Email_Sending(EmailBase email, dynamic? args) {
int UserRecordCount;
if (CurrentPageID() == "add" || CurrentPageID() == "edit") {
if (!Empty(KlantEmailadres.CurrentValue)) {
if (Convert.ToString(KlantEersteInformatieBriefMailen.CurrentValue) == "1") {
if ((Empty(KlantEersteInformatieBriefReedsVerzonden.CurrentValue)) || (Convert.ToString(KlantEersteInformatieBriefReedsVerzonden.CurrentValue) == "0")) {
// Haal gegevens uit de database
string klantEmailadres = ExecuteScalar("SELECT KlantEmailadres FROM Klant WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'").ToString();
string KlantEersteInformatieBriefMailen = ExecuteScalar("SELECT KlantEersteInformatieBriefMailen FROM Klant WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'").ToString();
string KlantEersteInformatieBriefReedsVerzonden = ExecuteScalar("SELECT KlantEersteInformatieBriefReedsVerzonden FROM Klant WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'")?.ToString();
string KlantEersteInformatieBriefReedsVerzondenDatum = ExecuteScalar("SELECT KlantEersteInformatieBriefReedsVerzondenDatum FROM Klant WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'")?.ToString();
string KlantNaam = ExecuteScalar("SELECT KlantNaam FROM Klant WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'")?.ToString();
email.Sender = "klankschalen@selexions.nl";
email.Recipient = klantEmailadres;
email.Cc = "";
email.Bcc = "";
email.Subject = "Klankschalen Limburg - informatie";
email.Format = "html";
email.Charset = "utf-8";
// Haal de e-mailinhoud op en vervang de placeholder met de klantnaam
string emailContentTemplate = "Beste " + KlantNaam + ",<br><br>" + ExecuteScalar("SELECT ContactInformatieMail FROM Contact").ToString();
email.Content = emailContentTemplate.Replace("{KlantNaam}", KlantNaam);
SendEmail(email.Sender, email.Recipient, email.Cc, email.Bcc, email.Subject, email.Content, email.Format, email.Charset);
// Update KlantEersteInformatieBriefReedsVerzonden en KlantEersteInformatieBriefReedsVerzondenDatum
Conn.Execute("UPDATE Klant SET KlantEersteInformatieBriefReedsVerzonden = 1 WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'");
Conn.Execute("UPDATE Klant SET KlantEersteInformatieBriefReedsVerzondenDatum = GETDATE() WHERE KlantIdComplex = '" + KlantIdComplex.CurrentValue + "'");
}
}
}
};
return true;
}