How Can I Send A File To Mail In Html Form Using Http Request In Nodejs Server Code?
What I am doing is when node server runs a user can type 1 or 2 or any other number.If user types 1 then I will print a message in response.When user types 2 then I will display a
Solution 1:
const nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: 'SenderMail@gmail.com',
clientId: 'ClienId from google console developers website',
clientSecret: 'clientSecret from google console developers website ',
refreshToken: 'RefreshToken from Oauth2 Playground website',
accessToken: 'accessToken from Oauth2 Playground website'
},
});
The below code solved my issue for sending the .pdf files
var mailOptions = {
from: ' <sendermail@gmail.com>',
to: 'Receivermail@gmail.com',
subject: 'Sample mail',
text: 'Hello !!!!!!!!!!!!!',
attachments: [{
// stream as an attachment
filename: 'text4.txt',//your file name with proper extention
content: fs.createReadStream('file.txt')
}]
};
Nodemailer official documentation about adding attachments of file
hope this works for you
Mysimple code which send's the pdf file through mail using nodemailer https://github.com/Muthukumars1994/sow_app/blob/master/controller.js
Post a Comment for "How Can I Send A File To Mail In Html Form Using Http Request In Nodejs Server Code?"