Skip to content

Commit 65145c6

Browse files
committedJun 9, 2023
using multer for send mail with attachment
1 parent 48a39d9 commit 65145c6

File tree

4 files changed

+300
-4
lines changed

4 files changed

+300
-4
lines changed
 

‎controllers/mail.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const nodemailer = require("nodemailer")
22

33
exports.sendMail = async (req, res) => {
44

5+
const { email, subject, text } = req.body
6+
const { originalname, buffer } = req.file
7+
58
let sender = nodemailer.createTransport({
69
service: 'Gmail',
710
auth: {
@@ -12,9 +15,13 @@ exports.sendMail = async (req, res) => {
1215

1316
let mail = {
1417
from: 'iamshiv20032003@gmail.com',
15-
to: "shivrajg20032003@gmail.com",
16-
subject: "test",
17-
text: "Send a email using node.js"
18+
to: email,
19+
subject: subject,
20+
text: text,
21+
attachments: {
22+
filename: originalname,
23+
content: buffer
24+
}
1825
}
1926

2027
sender.sendMail(mail, function (error, info) {

0 commit comments

Comments
 (0)