https://supertokens.com/ logo
Title
a

Alen

02/17/2023, 7:22 AM
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

rp

02/17/2023, 8:05 AM
hey @Alen - 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

Alen

02/17/2023, 8:11 AM
no we get a response code with 400 or 500 error. So based on that we want a fallback aproach
r

rp

02/17/2023, 8:12 AM
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

Alen

02/17/2023, 8:16 AM
yeah its synchronous. So I have a custom body to be send. how can override that ?
r

rp

02/17/2023, 8:17 AM
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

Alen

02/17/2023, 8:18 AM
This is how I'm sending the mail currently.
If you see
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

rp

02/17/2023, 8:20 AM
Then do
originalImplementation.sendEmail(input)
a

Alen

02/17/2023, 8:20 AM
Ok, but you are saying we cant provide custome body then ?
r

rp

02/17/2023, 8:20 AM
yea. If you want us to send the email, no custom body
if you use the smtp service (see docs), then you can
a

Alen

02/17/2023, 8:21 AM
Got it, thanks.