DEV Community

Cover image for Send mails using NodeJS

Send mails using NodeJS

Abayomi Ogunnusi on July 02, 2021

Hey, fams! today we are going to learn how to send e-mails, right from our IDE using NodeJS. The module of interest is called Nodemailer. ...
Collapse
 
suchitra_13 profile image
Suchitra

Thank you so much.
But I am facing difficulty in attachment sending part, I have tried 3 times but couldn't send only text sent!

Collapse
 
jlong4223 profile image
Jared Long

@Suchitra try adding an 's' to attachment: attachments: [{

I ran into the same thing with just text showing up and checked the nodemailer documentation on attachements. That little mispelling fix should do the trick.

Also, if you want to learn how to do this with a React frontend and Google OAuth2, check out my nodemailer article as well :)

Collapse
 
suchitra_13 profile image
Suchitra

Thank you so much
It's working fine now:)

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

@Suchitra

Do you have a folder where your image is stored?

Example:

attachment: [{
filename: "robocop.jpg", path: "./img/robocop.jpg"}]
};

Collapse
 
suchitra_13 profile image
Suchitra

I kept image file in same folder where my index.js is present.
So in this case I just wrote:

attachment: [{
filename: "robocop.jpg", path: "robocop.jpg"}]
};

But it is not working:(

Thread Thread
 
horomancer profile image
horomancer

shouldn't it be

path: "./robocop.jpg"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

@xchavez94x i have not used sendgrid before but I will look into it too...thanks for your contribution

Collapse
 
njokudanielo profile image
NJOKU DANIEL • Edited

Good content...Thanks

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi
Collapse
 
brandonwallace profile image
brandon_wallace

Nice article! Thanks for posting it.

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

@Reaper thanks for the contribution

Collapse
 
barelyhuman profile image
Reaper

Or you could use mailer.reaper.im to avoid setting this up in your code and instead let it do all the lifting.

Collapse
 
leandrodiascarvalho profile image
leandro dias de carvalho

Parabens pelo conteĆŗdo.

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

obrigado muito apreciado

Collapse
 
mvoloskov profile image
Miloslav šŸ³ļøā€šŸŒˆ šŸ¦‹ Voloskov

Kudos for teaching dotenv at the very beginning! I often see people pushing sensitive data into a public repo just because they treated environment security as an afterthought.

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

@njokdan You are welcome šŸ˜Š

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

@mvoloskov Thanks for the contribution. It's always safety first.

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

@salarc123 ... Thanks for the compliment. I will write as requested.

Collapse
 
silentashish profile image
Ashish Gautam

Your mail will ended up in spam if you use google smtp.

Collapse
 
xchavez94x profile image
xchavez94x

What is the difference than using sendgrid package ?