@@ -4,6 +4,7 @@ const bcrypt = require('bcrypt');
44const nodemailer = require ( 'nodemailer' ) ;
55const helper = require ( '../utils/helper' ) ;
66const Transaction = require ( '../models/transaction.model' ) ;
7+ const axios = require ( "axios" ) ;
78
89/* ------------ JWT Configs ----------- */
910
@@ -17,26 +18,20 @@ const jwt_headers = {
1718
1819//sendmail... sends email to the user using nodemailer
1920async function sendmail ( to , subject , otp ) {
20- var transporter = nodemailer . createTransport ( {
21- service : 'gmail' ,
22- auth : {
23- user : process . env . EMAIL ,
24- pass : process . env . PASS ,
21+ const options = {
22+ method : 'POST' ,
23+ url : 'https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send' ,
24+ headers : {
25+ 'content-type' : 'application/json' ,
26+ 'X-RapidAPI-Host' : process . env . X_RAPIDAPI_HOST ,
27+ 'X-RapidAPI-Key' : process . env . X_RAPIDAPI_KEY ,
2528 } ,
26- } ) ;
27- // mail configurations
28- var mailOptions = {
29- from : process . env . EMAIL ,
30- to : to ,
31- subject : subject ,
32- html : `Your otp is :${ otp } ` ,
33- } ;
34- await transporter . sendMail ( mailOptions , function ( error , info ) {
35- if ( error ) {
36- console . log ( error ) ;
37- } else {
38- console . log ( 'Email sent: ' + info . response ) ;
39- }
29+ data :
`{"personalizations":[{"to":[{"email":"${ to } "}],"subject":"${ subject } "}],"from":{"email":"[email protected] "},"content":[{"type":"text/plain","value":"Your otp is : ${ otp } "}]}` 30+ } ;
31+ axios . request ( options ) . then ( function ( response ) {
32+ console . log ( 'Email sent: ' + response . data ) ;
33+ } ) . catch ( function ( error ) {
34+ console . error ( error ) ;
4035 } ) ;
4136}
4237
0 commit comments