Page 1 of 1

Email_Sending - Receiving 2 emails instead of 1

Posted: Wed May 29, 2024 9:25 pm
by aiden

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;
}

Re: receiving 2 emails instead of 1

Posted: Thu May 30, 2024 8:55 am
by MichaelG

You have called the SendEmail() function yourself in the server event which will send another email. Just remove the line.


Re: Email_Sending - Receiving 2 emails instead of 1

Posted: Thu May 30, 2024 2:47 pm
by aiden

It works, thx!