Emailing using Velo

Is it possible to send an email to someone without first adding them to a contact list like in the example given here:

I am not sure what you mean. You should not be emailing without permission so you would need a user as a contact that has also agreed to be emailed, correct?

Hello Amanda,

I have permission. My email address was verified by WIX.

I’m creating a page with a form asking individuals to upload receipts for reimbursement. These individuals are most likely not members of the site. The form has a name field, email address field, an upload button, and a submit button.

After they submit the uploaded receipt photos, I’d like to send a thank you email along with a reference ID. I expect to simply have a method that looks like:

sendThankYouEmail(name, emailaddress){
refID =“1234”
sendmessage(name,emailaddress,“Thank you. RefID: " + refID”)
}

All the information needed is given in the form.

For the highlighted technique, a contactID is required to send out an email.
This requires that the individual creates an account and then logs in. Even then, only the logged in person gets the email. I would not be able to send to multiple email addresses (ie, notifications to the Financial Secretary and Treasurer). For this reason, I’d like to avoid that requirement.

I modified the referenced code and eventually got it to work. I had to use the wix-crm-backend version in order to remove the requirement that the person needed to be logged in. I did still have to create a new contact for that person, collect the new contactID, and then send the email using a triggered email template’s email ID

My question is if it was possible to just send an email without the additional step of adding the person as a contact and using triggered email templates.

Here is my working code:


Front End


import {setupAndSendEmail} from “backend/ mybackend.jsw”;
export async function submitButton_click(event) {
let emailaddress=$w(“#txtEmail”).value;
let name=$w(“#Name”).value
const contactInfo = {
name: {
first: name,
emails: [emailaddress],
}
};
let emailStatus= await setupAndSendEmail(contactInfo);
if (emailStatus){
console.log(“Message Sent”);
} else{
console.log(“Email was not sent”);
console.log(emailStatus);
}
}


backend (mybackend.jsw) file:


import {triggeredEmails, contacts} from ‘wix-crm-backend’;
export async function setupAndSendEmail(contactInfo) {
try {
// Generate a unique code based on the date
const d = new Date();
let myCode = “R” + d.getFullYear() + d.getMonth() + d.getDay() + d.getHours() + d.getMinutes() + d.getSeconds();
console.log(myCode)

    // pull email address from Wix Contacts 
    let myContactID = await contacts.appendOrCreateContact(contactInfo); 

    // send email to individuals 
    let options =  {variables:{ reimbursementId: myCode }} 
    await triggeredEmails.emailContact('Reimburse', myContactID.contactId,options); 
    return true 
} catch (error) { 
    console.log(error) 
    return false 
} 

}

Gotcha, i do not believe so but perhaps someone else passing through will have a suggestion

Update… the code only sent an email to me (the logged-in person on the site). Even if I entered a different name and email in “contactInfo”, the returned variable “myContactID” was mine, so I kept getting all the emails I sent out. I’m at a loss.

Update … so far Wix Velo support has provided me with suggestions that have not worked. At first, I thought using velo to create and send confirmation emails seemed like an easy task. I’m at a loss as to why Wix Velo team could not figure out how to do it. I’ve been working on this for almost 2 months. I’m really hoping someone in this velo community has successfully done this and is willing to share how they did it. Wix suggested I hire a professional. Thanks.