Triggered emails seem to be sent but are not received by any contact

Hello there. I used an example found in the web on how to register a user using an email for confirmation. The first part of this procedure concerns the creation of a contact, the creation of a token and the sending of a triggered email to the contact. This is the function that exists in the backend.

export async function approveBy3rdParty(contactInfo) {
 const contactId = await wixCrmBackend.createContact({ "emails": [`${contactInfo.email}`] });
    console.log("Contact created id: " + contactId);
 const tokenForEmail = await createToken(contactInfo, contactId);
    console.log("Token ready for email: " + tokenForEmail);
 await sendEmailVerification(contactId, tokenForEmail);
 }

The code for the sendEmailVerification function is seen below:

import wixCrmBackend from 'wix-crm-backend';
const verificationEmailId = 'register';

export function sendEmailVerification(contactId, approvalToken) {
 const obj = {
 'url': `https://elianagiak.wixsite.com/e-menus/approve?tokenRegister=${approvalToken}`
    }
    console.log("Before sendEmailFunction");    
    sendEmail(verificationEmailId, contactId, obj);
}

Finally, here is the code of sendEmail function:

function sendEmail(emailId, contactId, obj) {
 try {       
        wixCrmBackend.emailContact(emailId, contactId, {
 "variables": obj
        })
        .then(() => {
            console.log('email sent successfully');
 const options = {
 "deleteMembers": true
            };
            wixCrmBackend.deleteContact(contactId, options)
            .then( () => {
                console.log('contact was successfully deleted');    
            })
            .catch( (err)=> {
                console.log('Error in deleting contact: ', err.toString());
            });
        })
        .catch((err) => {
            console.log('err in sendEmail is ', err.toString());
        });
    } catch (err) {
        console.log("err", err.toString())
    }   
}

I also used an async version of the function:

async function sendEmail(emailId, contactId, obj) {
 try {
        console.log("Email id: " + emailId + " ContactId: " + contactId + " variables: " + obj.url);
 await wixCrmBackend.emailContact(emailId, contactId, {
 "variables": obj
        });

        console.log('email sent successfully');        
 const options = {
 "deleteMembers": true
        };
 await wixCrmBackend.deleteContact(contactId, options);
        console.log('contact with contact id ' + contactId +  ' was successfully deleted');
    } catch (err) {
        console.log("err", err.toString())
    }
}

The problem is that a few days ago I was receiving these emails (some times the email was sent but it was not received which was awkward since I did not receive any error on the site monitoring).
However, for the last two days, any email I use to test this code (any email used for registration), results in successful sending of the triggered email (according to site monitoring) while at the same time the email cannot be found neither on the inbox, nor in junk or any other folder.
It is very important to solve this issue since I already paid for a premium site and the above mentioned procedure is related to the registration of any clients I am expecting to have.

Thanks for your time,
George Louloudis

P.S: I also include a screenshot of the triggered email just to be sure I am using the correct code

Hi G louloudis ,

I’ve had an issue with Triggered emails on a website, however it was in Editor X. It stopped working for an unknown reason, and it started again for an unknown reason some weeks later.

I can’t see any problem within your code.

Hi verbaldancing,

thanks a lot for your prompt response. I am very dissapointed with the problem. I have spent more than 5 hours the last couple of days trying to figure out what am I doing wrong. It is good to know that there is no issue with the code, however I am a bit frustrated since according to your experience, triggered emails may stop working for unknown reason. As it is clear, triggered emails are very important for my site. They play a significant role on the registration procedure. To this end, if emails are not sent, users of my site cannot register.

@glouloudis By the way, is there any reason why are you deleting the contact at the end of the script? As I said, I don’t see any problem from the point of view of sending an email, however I don’t know much about the contact approval, because I haven’t used it myself.

Perhaps get the contact deleting bit out just to be sure for now, because javascript is funny with the order of events sometimes, and you can’t send an e-mail to a deleted contact.

@verbaldancing Good point. The reason I am deleting the contact is that if I go on with the process and register the user after clicking on the email link i am having duplicates on the contact list (two contacts for the same person). So, after careful reading of the api I decided that the best option is to only use the initial contact created for sending the email and afterwards deleting this contact. For sure, I plan on examining your point on the order of events. I believed that deleting the contact after receiving the promise of the emailContact function would not create any issue.