Can't send mail with Cloud Functions for Firebase - javascript

I'm trying to send an email from a Cloud Function using the sendmail package.
It works when I host my "send function" locally. And I can deploy the function without problems to my Firebase project.
In the log at Firebase I can see this message:
Error: queryMx ESERVFAIL hotmail.com
at errnoException (dns.js:28:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
I'm neither familiar with sending emails from servers or Cloud Functions for Firebase. My question is why I got this error and how I can make it work?
Here is an excerpt from my function:
sendmail({
from: body.name + ' ' + '<' + body.email + '>',
to: 'soerensmed#hotmail.com',
subject: 'Henvendelse via kontaktformular',
html: html,
}, function (err, reply) {
if (err) {
console.log(err && err.stack);
response.status(500).end()
}
else {
console.log(reply)
response.status(200).end()
}
});
I'm developing a website where people can contact me through a contact form. The goal is to receive an email with the message... If this approach isn't possible I'm open for suggestions on how I can set this contact-email-thing up using Angular and Firebase.

It will not work with cloud function with free spark account. You should upgrade as it is clearly defined in pricing section in network box. https://firebase.google.com/pricing/

Related

error: getaddrinfo ENOTFOUND on GET request, firebase function [duplicate]

Trying to make a request to Paypal's API using PayPal-node-SDK
exports.requestPayment = functions.https.onRequest((req, res) => {
return new Promise(function (fullfilled, rejected) {
paypal.payment.create(create_payment_json, {}, function (error, payment) {
if (error) {
rejected(error);
} else {
console.log("Create Payment Response");
console.log(payment);
res.status(200).send(JSON.stringify({
paymentID: payment.id
})).end();
fullfilled(payment);
}
});
});
});
but I'm constantly getting an error:
Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
Things I've tried:
Making a request to a totally different host, still ENOTFOUND
Wrapping the request with cors(req,res, ()=>{...})
Prepending https:// to the host
What is the problem?
You'll need to be on a paid plan to make external API requests.
Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/
in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.
I was having this issue because of weak internet, change the internet connection.
You need to include service account to the admin initialization. this fixed the same issue for me
Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator to see what you'd be charged for a given usage.
The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

Sending 500 ("Server Error") response when visiting any url in Sails App

I am using Sails and Mysql to handle the database of my app. I recently clicked on a chrome autofill URL that took me to a 404'd page, since that url localhost:1337/companies was not active in this project.
Ever since I did that, my app returns
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'
and
Details: Error: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'where clause'
any time I go to a url in my app. I tried cloning my app and relinking the database to no avail. I see this is a common issue people run into with sails, but none of the mentioned solutions were able to fix it for me.
Everything was working before I clicked that URL which makes me believe it may be a route issue, but the app still works, it will just fill up my terminal with the above errors.
Any help is greatly appreciated!
Edit: this is the custom API call I was working on in my controller.js when I started seeing the error:
winner: function (req, res) {
User.findOne({id: req.param('id')}).exec(function(err, user) {
if (err) {
return res.negotiate(err);
}
else {
var u = user;
u.totalwins++;
u.save();
sails.io.sockets.emit("chat", {verb:"score", data:{id: req.param('id'), name: user.name}});
}
});
}
Also receiving this error in my chrome-browser console:
:1337/user/quizzes Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Gmail, nodemailer, OATH2 refresh token not working

I've set up Nodemailer to work with Gmail using OAuth2. It works fine until the access token expires. At this point, despite having a refresh token, I get the following error message:
{
Error: Invalid status code 401
at ClientRequest.req.on.res (xxxxxxxxxxx)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:191:7)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:522:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
at TLSSocket.socketOnData (_http_client.js:411:20)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:191:7)
at readableAddChunk (_stream_readable.js:178:18)
at TLSSocket.Readable.push (_stream_readable.js:136:10)
at TLSWrap.onread (net.js:561:20)
type: 'FETCH',
sourceUrl: 'https://accounts.google.com/o/oauth2/token',
code: 'EAUTH',
command: 'AUTH XOAUTH2'
}
Here's my code. I've also tried including the refresh token and access token in the initial nodemailer setup, as well as including the expiry date. Each time I get the same result.
Nodemailer setup:
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
clientId: 'xxxxxxxxxx',
clientSecret: 'xxxxxxxxxx'
}
});
transporter.on('token', token => {
console.log('A new access token was generated');
console.log('User: %s', token.user);
console.log('Access Token: %s', token.accessToken);
console.log('Expires: %s', new Date(token.expires));
});
E-mail setup:
const mailOptions = {
from: xxxxxxxxx,
to: xxxxxxxxx,
subject: 'Test Subject',
text: 'This is a test',
html: '<p>This is a test</p>',
auth: {
user: 'xxxxxxxxxxxx',
refreshToken: 'xxxxxxxxxxxxx',
accessToken: 'xxxxxxxxxxxxx'
}
}
E-mail send
transporter.sendMail(mailOptions, function(err, info){
if(err){
return console.log(err);
}
console.log('Message %s sent: %s', info.messageId, info.response)
})
Can anyone suggest what may be going wrong?
I know i am too late on this post. But i came here as i was facing same issue yesterday. I have fixed the issue and the issue was a silly mistake which was not mentioned anywhere.
So issue was in the process to create refresh token and access token in the google playground page. I selected correct scope (https://mail.google.com) but while creating code and refresh token i did not added my app client id and secret and google was taking a client id and secret of playground by default. So be careful to add your app's client id and secret in the playground.
To add your client id and password. Click on right top corner setting button. Click on checkbox saying use your own credentials and click on close. now if we create access refresh token Google will ask permission for our app instead of Google Playground.
It will resolve the 401 issue. This was not mentioned anywhere on any card created.
Check this SO post to direct you about the discussion on "refresh token", see answers by RobKohr and Radioreve.
And maybe this OAuth2 samples can help you to check the difference from your code.
Reference from Nodemailer site:
OAuth2 allows your application to store and use authentication tokens
instead of actual login credentials. This is great for security as
tokens or valid only for specific actions and can be easily revoked
thus, once stolen, can’t to as much harm as actual account
credentials. OAuth2 authentication in Nodemailer is mostly used with
Gmail and G Suite (née Google Apps) even though there are other
providers that support it as well.
Access Tokens needed for OAuth2 authentication are short lived so
these need to be regenerated from time to time. Nodemailer is able to
use both 3LO and 2LO to automatically regenerate the tokens but you
can also handle all token specific yourself.
You can refer to this SO post for addition information.

ReactNative Facebook Login Issue

I followed the steps here (https://developers.facebook.com/docs/react-native/configure-ios) for facebook login with iOS. I'm using a custom login call from my own component. The login confirm dialog comes up fine but when I hit "Continue" mobile safari seems to get stuck:
I'm seeing a bunch of weird warnings:
: -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
requesting pasteboard fb_app_attribution
Apr 12 08:08:42 MacBook-Pro pasted[69862] : ...requesting pasteboard fb_app_attribution completed. Error: (null)
Apr 12 08:08:56 SafariViewService[70243] : Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
But none really yield any good search results. Any help would be amazing. Thanks.
P.S. My code for calling login:
handleFacebookPress() {
LoginManager.logInWithReadPermissions(['email']).then(
(result) => {
if (result.isCancelled) {
console.log('Login was cancelled');
} else {
console.log('Login was successful with permissions: '
+ result.grantedPermissions.toString());
}
},
(error) => {
console.log('Login failed with error: ' + error);
}
);
}
I had the same issue. I was able to fix it by adjusting the Oauth url in the facebook application portal to be https://localhost:8081 as my react native localhost was using port 8081

Receiving Twilio 31201 error, despite having well-formed token

I'm using the following code from the Twilio Programmable Video Javascript Quickstart Guide, trying to Initialize the SDK with an access token:
https://www.twilio.com/docs/api/video/guide/identity
// Create an AccessManager to manage our Access Token
var accessManager = new Twilio.AccessManager('$TWILIO_ACCESS_TOKEN');
// Create a Conversations Client and connect to Twilio's backend
conversationsClient = new Twilio.Conversations.Client(accessManager);
conversationsClient.listen().then(function() {
console.log('Connected to Twilio!');
}, function (error) {
console.log('Could not connect to Twilio: ' + error.message);
});
But before even hitting the "could not connect to Twilio" error message designed into the above code, I get the following console error:
twilio-conversations.min.js:91 Client ERROR r {_errorData: Object, name: "LISTEN_FAILED", message: "Gateway responded with: 31201 Unknown authentication error"}
I'm testing this on an https-enabled development server, via ngrok.io. I've followed the code in the tutorial (link above) carefully. Does anyone understand what causes this cryptic 31201 error?

Categories

Resources