-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
78 lines (58 loc) · 2.48 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express');
const app = express();
const {GoogleAuth} = require('google-auth-library');
const { google } = require('google-auth-library');
const {OAuth2Client} = require('google-auth-library');
const keys = require('./oauth2.keys.json');
// Your Express app configuration
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
async function main() {
const oAuth2Client = await getAuthenticatedClient();
// Make a simple request to the People API using our pre-authenticated client. The `request()` method
// takes an GaxiosOptions object. Visit https://github.com/JustinBeckwith/gaxios.
const url = 'https://people.googleapis.com/v1/people/me?personFields=names';
const res = await oAuth2Client.request({url});
console.log(res.data);
// After acquiring an access_token, you may want to check on the audience, expiration,
// or original scopes requested. You can do that with the `getTokenInfo` method.
const tokenInfo = await oAuth2Client.getTokenInfo(
oAuth2Client.credentials.access_token
);
console.log(tokenInfo);
}
var bodyParser=require('body-parser');
var cors=require('cors');
var router=express.Router();
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(cors());
app.use('/api',router);
router.use((request,response,next)=>{
console.log('middleware');
next();
})
const nodemailer = require('nodemailer');
router.route('/email/').post(async (request,response)=>{
const{from,to,subject,text}=request.body;
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: '[email protected]', // Your Gmail email address
clientId: '902622774904-mchfoteulp9cm3dljc9e165g6krijjdd.apps.googleusercontent.com',
clientSecret: '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',
refreshToken: '1//04MTy0K4hi_uwCgYIARAAGAQSNwF-L9IrQ4VS1vpylkhUR_0cuy1QMkY3-XyShHlyAAQBO03jnYhog9G3c2rreLuajp2K0J8s_kA', // Retrieve this from the OAuth2 callback
},
});
const mailOptions={from,to,subject,text};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.error(error);
}
console.log(`Email sent Successfully: ${info.response}`);
response.end();
});
})