Hello,
I hope you can help me with this issue:
I'm using SendGrid REST API Ver.3 and Javascript to send emails from my website. All of my emails are being sent successfully, I actually receive the emails instantaneously and fully HTML formatted in my inbox. Problems is, I never receive any “ok” response from the SendGrid servers; they keep me waiting for a response permanently, so my code gets stuck on the "Return" Promise().
If I send a bad request on purpose, I receive an error response immediately, but when I send a good request, I receive no response at all, not even a null or empty string or a timeout for waiting that long.
Fact is, SendGrid is processing my request successfully because I get the email in my inbox, but I never get any response.
Any help will be appreciated,
Thank you,
HERE IS MY CODE:
export function SendGridFetch2 (APIKey, Sender, Recipient, Subject, HTMLBody)
{
const MyURL = "https://api.sendgrid.com/v3/mail/send";
const MyHeaders = {"Content-Type":"application/json", "Authorization":"Bearer " + APIKey};
const MyBody = {"personalizations":[{"to": [{"email":Recipient, "name":"XXXX"}]}], "from":{"email":Sender, "name":"YYYYY"}, "subject":Subject, "content":[{"type":"text/plain","value":"Your email client does not support HTML"},{"type":"text/html","value":HTMLBody}]};
return fetch(MyURL, {"method":"POST", "headers":MyHeaders, "body":JSON.stringify(MyBody)}).then(Response => Response.json());
}
HI @Cornielles,
If you are using the official @sendgrid/mail SDK, you can retrieve your response like this.
If you do not want to use the SDK, please reach out to our support team for further assistance. This issue tracker is dedicated to issued related to the official SDK.
Thank you!
With Best Regards,
Elmer
Thanks so much Elmer, I appreciate your prompt response.
Yes, I'm not using the SDK, just a simple HTTP REST fetch/request. And the reason I posted in here is because the support team in SendGrid haven't answered me in a while and I thought you guys would help me.
I was using the API Ver.2 and I was getting responses from your servers on each single request, but that API had problems processing large HTML Files. So your Support Team suggested me to migrate to API Ver.3. Yes, I was in contact with them already and they were helping me with my previous issue.
I migrated to API Ver.3 and I implemented it successfully, my initial issue with the large HTML files was resolved with this new API, but now this API only send me a response when I send bad requests, when I send a good request, there is no response at all. My code gets stuck waiting for one.
The odd thing is, my request gets processed successfully because I receive the email in my inbox perfectly just a second after my request is sent. And I'm very grateful with you guys for helping me on this.
Problem is, even though my request is being processed successfully, no response is being sent back. So I replayed back to my original ticket (which is still open) but I haven't received an answer from your helpdesk ever since. It's been a week now and I need to get this running ASAP.
Thanks again Elmer,
I will reply once more to my ticket to see if I get any answer.
Best,
-Luigi
Hello @Cornielles,
Thanks for taking the time to provide further detail. There should be a 202 status code with an empty body for a return. Perhaps you are only reading the response body on return?
My recommendation for utilizing v3 is our official SDK. It is very easy to use.
For troubleshooting, I would recommend utilizing our interactive documentation and perhaps some cURL command line testing.
I hope that helps.
With Best Regards,
Elmer
Hi Elmer,
With the help of WIX Help Desk, I finally figured this out.
If there is a bad request from SendGrid, your response can be JSON() Validated, but for some reason, when I have a successful response, I get just an empty string from SendGrid as a response, so my JSON() validation failed to understand your response.
Now I just use your straight raw answer as a string without treating it:
EMPTY = Success
NOT EMPTY = Something went wrong.
In case you would like to dig deep into this, it is confirmed that an empty string is being returned upon "success" with your API v3 when using an HTTP CALL or FETCH. When I was working with your API Ver2, I always received "{message:success}" upon success.
Thanks for your support Elmer,
I'm closing this issue
-Luigi
Hi @Cornielles,
Thank you for taking the time to share the solution!
Hi @thinkingserious ,
I'm using the @sendgrid/mail package to send emails. How exactly do you know in the callback if an email has been delivered or not? I get a statusCode of 202 for fake emails as well as real emails.
Maybe I'm approaching this in the wrong way?
Hello @kunalnagar,
The 202 is letting you know that we received your request. To find out if your emails are delivered, you can utilize our Event Webhook or the email activity feed.
With Best Regards,
Elmer
@thinkingserious I got the 202 status code but the emails i sent it to didn't receive mail. please help me out. am new to programming
Most helpful comment
Hi Elmer,
With the help of WIX Help Desk, I finally figured this out.
If there is a bad request from SendGrid, your response can be JSON() Validated, but for some reason, when I have a successful response, I get just an empty string from SendGrid as a response, so my JSON() validation failed to understand your response.
Now I just use your straight raw answer as a string without treating it:
EMPTY = Success
NOT EMPTY = Something went wrong.
In case you would like to dig deep into this, it is confirmed that an empty string is being returned upon "success" with your API v3 when using an HTTP CALL or FETCH. When I was working with your API Ver2, I always received "{message:success}" upon success.
Thanks for your support Elmer,
I'm closing this issue
-Luigi