-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61e3a24
commit 77cf18e
Showing
4 changed files
with
550 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import nodemailer from "nodemailer"; | ||
import "dotenv/config"; | ||
|
||
export const createContactUs = async (req, res) => { | ||
const { mail, subject, message } = req.body; | ||
|
||
try { | ||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
host: "smtp.gmail.com", | ||
port: 587, | ||
secure: false, | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS, | ||
}, | ||
tls: { | ||
rejectUnauthorized: false, // Disable strict SSL verification | ||
}, | ||
}); | ||
|
||
const mailOptions = { | ||
from: mail, | ||
to: process.env.EMAIL_USER, | ||
subject: subject, | ||
text: message, | ||
}; | ||
|
||
// Send mail with defined transport object | ||
transporter.sendMail(mailOptions, (error, mailOptions) => { | ||
if (error) { | ||
console.error("Error occurred: " + error.message); | ||
return; | ||
} | ||
}); | ||
|
||
res.status(200).json({ | ||
status: "success", | ||
message: "Your contact request has been successfully received.", | ||
}); | ||
} catch (err) { | ||
console.error(`Error at transport : ${err}`); | ||
res.status(500).json({ | ||
status: "error", | ||
message: | ||
"There was an error sending your message. Please try again later.", | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import express from 'express'; | ||
const router = express.Router(); | ||
import { createContactUs } from "../controllers/contactusController.js"; | ||
|
||
router.post("/contactus", createContactUs); | ||
|
||
export default router; |
Oops, something went wrong.