Hi, I'm using sendgrid to send mails with OTP and magic link. So sometimes user don't receive mails....
a
Hi, I'm using sendgrid to send mails with OTP and magic link. So sometimes user don't receive mails. So in that case I want to use default supertokens mailing system as a callback to this issue. Is that possible ?
r
hey @alen_george - how do you know if a user has not received the email? Do you assume thats the case if they click on the resend button?
a
no we get a response code with 400 or 500 error. So based on that we want a fallback aproach
r
right. So in that case, you can just call the original implementation of sendEmail and that should fallback on the default method
this is assuming that the call to sendgrid and it returning the status is synchronous.
a
yeah its synchronous. So I have a custom body to be send. how can override that ?
r
So for that, you need to use the smtp service we have and configure your smtp settings + define your custom body in there. Then calling the original implementation will use the smtp service. if you want to fallback on us sending the email, then you can't customise the template.
a
This is how I'm sending the mail currently.
If you see
Copy code
sgMail
 .send(msg)
 .then(([response, body]) => {
          console.log('Email sent successfully.');
           console.log(response.statusCode);
 })
 .catch((error) => {
         console.error(error)
})
If the
response.statusCode
is 400 or 500 related then I want the mail to be send from supertokens.
r
Then do
originalImplementation.sendEmail(input)
a
Ok, but you are saying we cant provide custome body then ?
r
yea. If you want us to send the email, no custom body
if you use the smtp service (see docs), then you can
a
Got it, thanks.
65 Views