0

What I want to do is to send user a mail, a user's password , from my node js rest api. I want to know how to send email using gmail api and api keys only.

6
  • Google has an API reference for gmail and even a section on how to use it from node.js. Have you read that? What code have you tried? Where did you get stuck. We don't just write code for people who don't show that they've even tried or describe anything about where they got stuck and what problem they ran into. Commented Mar 20, 2017 at 7:10
  • I had tried that code but that code using 0auth id which force to authenticate by providing url from code what I want to do is to just send an email without authenticating the url but just using api keys which I have created in project google console. Commented Mar 20, 2017 at 7:32
  • I think you have to authenticate. You can't use only API keys. An API key identifies your API usage, but doesn't authenticate you into the account. Commented Mar 20, 2017 at 7:36
  • Google discontinued client login (login and password) on all of its APIs in 2015 you will have to go though the SMTP server. Commented Mar 20, 2017 at 8:02
  • @DaImTo what should all those extra redundant tags do something good for? google-api gmail-api google-oauth2 google-client-login cannot be more overstuffed. It does not help anyone (but perhaps you, as a tag hunter) Please read stackoverflow.com/help/tagging Commented Mar 20, 2017 at 8:36

2 Answers 2

2

Google discontinued client login (login and password) on all of its APIs in 2015. You cant access a Google API with login and password. Your users will need to authenticate using Oauth2.

API key is used for accessing public data only. Gmail is private user data and requires you to have access in order to access the data.

If you must use the login and password then I suggest you try and go though the SMTP or IMAP servers. I am not a node dev sorry I can not help you with that.

Sign up to request clarification or add additional context in comments.

Comments

0

If what you want is to send an email using Gmail API without the need for authentications you must use a service acount and use jwt to authenticate.

example code:

const google = require('googleapis');
const gmail = google.gmail('v1');

const key = require('./mailing-bd0ff2b11546.json')//service acount jwt auth

    let jwtClient = new google.auth.JWT(
        key.client_email,
        null,
        key.private_key,
        ['https://mail.google.com/'],
        '<mail to suplant>'
    );
    function getMessagesList(data) {
        return new Promise((resolve, reject) => {


            jwtClient.authorize(function (err, tokens) {
                if (err) {
                    console.error(err);
                } else {
                    gmail.users.messages.list({
                        auth: jwtClient,
                        userId: 'me',
                        labelIds: 'INBOX'
                    }, (err, messageList) => {

                   ...
                   ...
                   ...

Here are some links to documentation: Creating a service account

stackoverflow example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.