Email_Sending - Receiving 2 emails instead of 1

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
aiden
User
Posts: 29

Email_Sending - Receiving 2 emails instead of 1

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

MichaelG
User
Posts: 1160

Post by MichaelG »

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


aiden
User
Posts: 29

Post by aiden »

It works, thx!


Post Reply