Skip to content
Sign upLog in
← Back to Community

Send emails with NodeJs w/ Nodemailer

Profile icon
PixelNinjaHacker

NodeMailer

Well, well, well,

It's Christmas, and boy, do I have a gift for you!

But first, a quick intro:

I joined repl.it not to long ago to learn to code. I had no clue about Nodejs, I never planned to post on learn, but here I am.

My mission:

Have a working way to send emails using nodemailer! Did I do it? Yes!

Setup:

You will need to create a .env file which must include 2 lines:
pass=YOUR GMAIL PASSWORD
pin=ENTER 6 DIGIT PIN

You will also need to change
YOUR USERNAME In public/send.html
To your repl.it username. Then you're all set!

Well, almost,

If you have 2fa on your Gmail account, you need to setup an app password using the instructions at the bottom of the repl. Good luck!


Welp, I'm Out

Hope that setup wasn't to much! If you want to preview what the send page will look like, click here
If you rename your repl, make sure you change the URL in send.html!


Please let me know if I have forgotten anything! Share any adaptions below! /

Voters
Profile icon
wonk2
Profile icon
QueenRia
Profile icon
ToldFable
Profile icon
decomp
Profile icon
mic2en
Profile icon
XCode101
Profile icon
hughese2006
Profile icon
nmquaan
Profile icon
techgeek680
Profile icon
Loganjackson06
Comments
hotnewtop
Profile icon
PixelNinja

I also forgot to add that you need to change your email on line 13 and line 20 in index.js. any problems msg me!

Profile icon
almostStatic

@RossJames
thank you i spent years tryinf to figure this out.

Profile icon
arjun418

Doesnt work :(

Profile icon
PixelNinja

@arjun418
I, can confirm this still works if you follow the above instructions

Profile icon
arjun418

@PixelNinja
it doesn't send the message and gives an error :

server started
/home/runner/NodeJs-Node-Mailer-Sample/index.js:27
if(e) {
^

ReferenceError: e is not defined
at /home/runner/NodeJs-Node-Mailer-Sample/index.js:27:3
at /home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/mailer/index.js:226:21
at /home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/smtp-transport/index.js:282:36
at SMTPConnection._actionAUTHComplete (/home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/smtp-connection/index.js:1505:20)
at SMTPConnection. (/home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/smtp-connection/index.js:544:26)
at SMTPConnection._processResponse (/home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/smtp-connection/index.js:929:20)
at SMTPConnection._onData (/home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/smtp-connection/index.js:736:14)
at TLSSocket.SMTPConnection._onSocketData (/home/runner/NodeJs-Node-Mailer-Sample/node_modules/nodemailer/lib/smtp-connection/index.js:189:44)
at TLSSocket.emit (events.js:314:20)
at TLSSocket.EventEmitter.emit (domain.js:483:12)
repl process died unexpectedly: exit status 1

Profile icon
PixelNinja

@arjun418
A I see the issue. I updated the code so that it would fix with forks. Thanks

Profile icon
arjun418

what is the pin?

Profile icon
BenjaminPS

Hi Thanks for this ! I have a question though : I was told never to put a password in .env file on a repl. Is there any security risk here ?

Profile icon
PixelNinja

@BenjaminPS
If you aren't a hacker, your code is visible to anyone. This is why you need a .env else anyone can see tokens/whatever else you put in.

Profile icon
BenjaminPS

@PixelNinja

I see. The thing is : I would like to share my repl with everyone and get an Email (sent from the Repl via a newly created Email address) everytime someone runs it. Do you think this is unsafe ?

Profile icon
PixelNinja

@BenjaminPS
The repl will only send an email when the correct pin is entered. If someone is guessing your pin, make it longer. It's not unsafe if used properly

Profile icon
PixelNinja

@BenjaminPS
Oh, sorry, just re-read it. Yes, it would be unsafe as that would mean your password would have to be public

Profile icon
BenjaminPS

@PixelNinja
I understand... Thanks !
I wish there was a way I'd get a notification every time my Repl are used. It's seems so simple yet I can't seem to find a way to achieve this.

Profile icon
PixelNinja

@BenjaminPS
You can see when your repl it forked. Check the spotlight page
Preview[1]

Or go onto a repl and add "?v=1" to the repl URL

Profile icon
BenjaminPS

@PixelNinja
The thing is, I don't share my Repl so people fork it. I use Repl to share some online-tools with people (who don't know anything about python) so they can use the programs directly via my Repl. It works great in theory but I have no idea how many people do use it.

Profile icon
PixelNinja

@BenjaminPS
That is currently not possible. Try the feedback board.

Profile icon
hughese2006

Hey what is the Google Six digit pin?

Profile icon
PixelNinja

@hughese2006
Huh?

Profile icon
hughese2006

Thanks for replying but I have figured it out.

@RossJames

Profile icon
techgeek680

Yes ! I need this!