Learn to Code via Tutorials on Repl.it!

← Back to all posts
Send emails with NodeJs w/ Nodemailer
h
PixelNinja (319)

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! \/

Comments
hotnewtop
PixelNinja (319)

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!

almostStatic (112)

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

AdCharity (1322)

This is genius thanks

AdCharity (1322)

@RossJames can you send automated messages with this? the .env file is pretty smart too

PixelNinja (319)

Hey! @AdCharity , depending on what you mean, you could edit the code to call the function whenever you wanted or add a set interval function which runs every X ms. What sort of purpose was you thinking? Remember Gmail has a rate limit of about 2 seconds. You can send to multiple emails at a time with the to address as

to: '[email protected], [email protected]',

.env files are used to hide variables you don't want people to see, repl.it has a tutorial on them.

AdCharity (1322)

@RossJames cool :D (sorry late reply didn't see it)

AdCharity (1322)

@RossJames Yo something that might come up (probably should add this to your tutorial.) I heavily advise creating a new email for this purpose and then allow insecure apps here: https://myaccount.google.com/lesssecureapps
It is highly likely that Google will block node mailer as a robotic sign in attempt; so allowing insecure apps will most likely allow node mailer to work (and this is also why you'd want to make a new email soley for this purpose)

BenjaminPS (2)

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 ?

PixelNinja (319)

@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.

BenjaminPS (2)

@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 ?

PixelNinja (319)

@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

PixelNinja (319)

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

BenjaminPS (2)

@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.

PixelNinja (319)

@BenjaminPS You can see when your repl it forked. Check the spotlight page

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

BenjaminPS (2)

@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.

PixelNinja (319)

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

hughese2006 (0)

Hey what is the Google Six digit pin?

hughese2006 (0)

Thanks for replying but I have figured it out. @RossJames

techgeek680 (73)

Yes ! I need this!