How to access the google scope to send email after user logs in with oauth?

#1

@notbrent I’m trying to read, edit and send emails from the gmail.

So this code works for auth with google.

try {
const result = await Expo.Google.logInAsync({
androidClientId: ‘99925chanded046008-bj57bn76upqv0st2changed8rmqav.apps.googleusercontent.com’,
iosClientId: ‘99changed46008-klt93d6s78a56gqjua5jqrbdchd4nd82.apps.googleusercontent.com’,
scopes: [‘profile’, ‘email’],
});

      if (result.type === 'success') {
        console.log('128 -  google success ');

so i edited the scope to do so, like below.

scopes: [‘profile’, ‘email’, ‘https://mail.google.com/’],

it doesnt give me any error message.

but i dont get the screen like this on the simuloator like it get on the web browser.

Question : Am i on right track ?

I thikn i should get this screen but i dont get it …

Basically im confused which path to go :

Questions:

  1. when use use the google auth via the expo’s google auth on mobile, ( even after adding the scopes ) I dont get the screen where google asks user that this guy wants to access your emails. So i wonder if it works.

If that would work, id simply send the tokens to my backend and get it working.

But the nodemailer on the server side requies the client id to be web based i.e it requires the

googleclientID:
googleClientSecret:

1.2) would the tokens ( refreshToken) generated from the expo would work with node mailer ?

  1. Second option is to have user to signin from web and get the persmission to send emails. But this woudl require each user to do the 2 step whenver somebody new signup.

So nodemailer requeres few tokens

Heres the setup for nodemailer

let transporter = nodemailer.createTransport({
host: ‘smtp.gmail.com’,
port: 465,
secure: true,
auth: {
type: ‘OAuth2’,
clientId: ‘950changed08-u3uqcijecb4pipt2ob41sdedkdm6q12p.apps.googleusercontent.com’,
clientSecret: ‘2T_Achanced-kYQCK-xoAlb’
}
});

transporter.sendMail({
from: ‘fromemail@gmail.com’, // It has to be the email that user logged in with.
to: ‘toemail@gmail.com’,
subject: ‘Message’,
text: ‘I hope this message gets through!’,
html: ‘Hi there, coming with the html’, // html body
auth: {
user: ‘useremail@gmail.com’,
refreshToken: ‘1/vSlgpvWgQeBzeVWgLAMhjBz7LT4XzpGLMFa_h0jYigRAqoMDtRglva6nh7oLmYkv’,
accessToken: ‘ya29.GlCHANGEDq01l87lSQRshAerNUol2yV4xf2GTyfwWQG8SGkQSu-o1X4OF5k1zSWtQCHANGEDMYqL1hkxuwWc8NMDnZic9MnDzB96uByM’,
expires: 1484314697598
}
});

Question is : the Tokens passed from client side will play well with nodemailer ( backend ) ?

0 Likes

closed #2

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

0 Likes