I am trying to setup email function with sendgrid. If everything is filled out correctly, the email is properly sent.
But I need to catch the error if a mail could not be sent.
In the frontend code there is a code trying to catch an error.
(CODE FROM EXAMPLE FRONTEND)
…
. catch (( error ) => {
let dataObj = {
status : “failure” ,
email : $w ( ‘#toEmail’ ). value
};
wixWindow . openLightbox ( “Message” , dataObj );
Unfortunately it never catches an error.
I can reconstruct this by doing the following:
Sendgrid needs a Sender Authentication . You can not just put any sender domain in the "from email field. (see SendGrid , if you are a registered user of sendgrid).
So when I put a NON authenticated sender email adress in the examples form, the mail will NOT be sent but the appearing lightbox says: "Your email message was sent to: >>YOUR TO EMAIL ADRESS<< "
So obviously there was an error from sendgrid API but this error is not catched.
I believe it has to do with the promise in the frontend code is resolved BEFORE a promise in the backend code is resolved.
So the frontend code promise must wait until the backend promise is resolved. How can we achieve this?
Or is there another way to catch a 3rd-party error message from code in the backend?
Hi Yisrael
I did not write my own code yet:
I tried the example ( Wix Code - Examples ).
I entered my sendgrid key, I have one.
Then: As a sender I used an email adress (that works and that I have access to) which has a domain that is not authorised in my sendgrid account.
As a receiver I entered my private email adress, that I can check.
Result: The message lightbox tells me that the email was sent but no email ever was sent to my private mailbox.
I would expect that the lightbox shows me the error message.
2nd try: Now I used as a sender an email which has a domain that is authorized in my sendgrid account. As a receiver I use again my private email adress.
Result: Message tells me that the email was sent and indeed I received it.
So no code to show you at this point. Maybe there is something wrong in my sendgrid account? But then again: Why does it work when sent with a authorized domain?
I suspect that this might be something on the Sendgrid side. It appears as if the code and the Wix side seems OK.
I seem to recall that some users had issues regarding the way certain types of Sendgrid accounts handled some email deliveries. What type of Sendgrid account do you have? I think that users were saying that premium Sendgrid accounts “worked better”. Have you checked the Sendgrid activity logs?
Unfortunately we are unable to troubleshoot Sendgrid. You should try Sendgrid’s technical support to see if they can shed any light on this problem.
If you suspect that there is a Wix bug, you should contact Wix Customer Care .