Just trying to send an email with cloud functions
const functions = require('firebase-functions')
const express = require('express')
const cors = require('cors')
const mailService = require('@sendgrid/mail')
const bodyParser = require('body-parser')
//Constants
const SENDGRID_API_KEY = 'Myapikey'
//Set up
const app = express()
app.use(bodyParser.json())
app.use(cors({ origin: true }))
app.post('/send', async (req, res) => {
mailService.setApiKey(SENDGRID_API_KEY)
const { name, email, message } = req.body
const emailContent = {
to: '[email protected]',
from: '[email protected]'',
subject: `subject`,
text: `some message`,
}
try{
const response = await mailService.send(emailContent)
res.json({message: 'message sent'})
} catch(error){
const { message, code, response } = error
res.json({message, response})
}
})
exports.api = functions.https.onRequest(app)
Looks like a DNS issue. I read elsewhere (stackoverflow) that you need to be on a paid plan to make external Requests on firebase functions. Does it work locally on your laptop?
@aroach
Does it work locally on your laptop?
No, is not working locally.
Is it Firebase issue or Sendgrid?
Thanks
PS: I think for locally you meant calling the function locally rather than being already deployed? If yes, in that case my function is live
@aroach turns out it was true: https://firebase.google.com/support
And after upgrade my plan I could send the message.
Thanks
This is a fire-base issue. If you are using Free(Spark Plan) account you can only use Google services if you are using external services you have to pay for that.
https://firebase.google.com/pricing/
Upgrade your plan(Flame Plan or Blaze Plan) you can send emails through SendGrid.
@kadnan0900 i upgraded to blaze plan but still getting getaddrinfo ENOTFOUND api.github.com api.github.com:443 error.
Also getting the error. Interestingly, it worked once, then didn't work again. On the Blaze plan in firebase, verified I'm using correct API keys, the API key creds are correct. Testing locally with firebase emulator/UI, getting this error.
Using:
"@sendgrid/mail": "^7.1.1",
"firebase-admin": "^8.12.1",
"firebase-functions": "^3.6.2"
Looks like a DNS issue. I read elsewhere (stackoverflow) that you need to be on a paid plan to make external Requests on firebase functions. Does it work locally on your laptop?
Its working locally. But not on deployment
Also getting the error. Interestingly, it worked once, then didn't work again. On the Blaze plan in firebase, verified I'm using correct API keys, the API key creds are correct. Testing locally with firebase emulator/UI, getting this error.
Using:
"@sendgrid/mail": "^7.1.1", "firebase-admin": "^8.12.1", "firebase-functions": "^3.6.2"
Any luck? We're experiencing this issue ourselves on the Blaze plan.
Most helpful comment
Looks like a DNS issue. I read elsewhere (stackoverflow) that you need to be on a paid plan to make external Requests on firebase functions. Does it work locally on your laptop?