-
Notifications
You must be signed in to change notification settings - Fork 194
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
f56c151
commit b8feb24
Showing
6 changed files
with
73 additions
and
17 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
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,40 @@ | ||
const nodemailer = require('nodemailer'); | ||
const subscribeToEmail = async (req, res) => { | ||
const { email } = req.body; | ||
|
||
if (!/^[^\s@]+@gmail\.com$/i.test(email)) { | ||
return res.status(400).send('Invalid Gmail address.'); | ||
} | ||
|
||
let transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS, | ||
} | ||
}); | ||
|
||
|
||
let mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: email, | ||
subject: 'Thank you for subscribing IMAGINE AI!', | ||
text: 'Thank you for subscribing to our platform!', | ||
html: '<h1>Thank you!</h1><p>You have successfully subscribed to our platform.</p>', | ||
}; | ||
|
||
|
||
|
||
try { | ||
await transporter.sendMail(mailOptions); | ||
console.log('Email sent successfully to ' + email); | ||
res.status(200).send('Subscription successful. Thank you email sent!'); | ||
} catch (error) { | ||
console.error('Error sending email: ', error); | ||
res.status(500).send('Error sending email.'); | ||
} | ||
} | ||
|
||
module.exports = { | ||
subscribeToEmail, | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
const express = require('express'); | ||
|
||
const { subscribeToEmail } = require('../controllers/subscribeController'); | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/', subscribeToEmail); | ||
|
||
module.exports = router; | ||
|
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