-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #387 from AyushSharma72/newsletter
added news letter api @387
- Loading branch information
Showing
2 changed files
with
41 additions
and
14 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 |
---|---|---|
|
@@ -20,37 +20,64 @@ const subscribeNewsletter = async (req, res) => { | |
const newSubscriber = new Newsletter({ email }); | ||
await newSubscriber.save(); | ||
|
||
// Configure the transporter | ||
Configure the transporter | ||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: process.env.EMAIL_USER, // Your email | ||
pass: process.env.EMAIL_PASS, // Your email password (use environment variables in production) | ||
user: process.env.EMAIL_USER, // Use environment variables in production | ||
pass: process.env.EMAIL_PASS, | ||
}, | ||
}); | ||
|
||
const mailOptions = { | ||
from: "[email protected]", | ||
to: email, | ||
to: email, // Send confirmation email to the subscriber's email | ||
subject: "Thank you for Subscribing to Our Newsletter", | ||
html: ` | ||
<div style="font-family: Arial, sans-serif; text-align: center;"> | ||
<h2>Thank You for Subscribing!</h2> | ||
<p>Dear Subscriber,</p> | ||
<p>We are thrilled to have you with us. Stay tuned for our latest updates and offers!</p> | ||
<a href="https://bitbox-in.netlify.app/" | ||
style="display: inline-block; padding: 10px 20px; margin-top: 20px; color: white; background-color: #007BFF; text-decoration: none; border-radius: 5px;"> | ||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; border-radius: 8px; overflow: hidden;"> | ||
<!-- Header --> | ||
<div style="background-color: #4A90E2; padding: 20px; text-align: center; color: white;"> | ||
<img src="cid:welcomeImage" alt="Welcome" style="width: 120px; margin-bottom: 10px;" /> | ||
<h1 style="font-size: 24px; margin: 0;">Thank You for Subscribing!</h1> | ||
</div> | ||
<!-- Body --> | ||
<div style="padding: 30px; background-color: #f8f8f8; text-align: center;"> | ||
<h2 style="color: #333; font-size: 20px; margin-bottom: 15px;">Welcome to the BitBox Community!</h2> | ||
<p style="font-size: 16px; color: #555; line-height: 1.6; margin: 0 0 20px;"> | ||
Dear Subscriber, | ||
</p> | ||
<p style="font-size: 16px; color: #555; line-height: 1.6; margin: 0 0 20px;"> | ||
We’re thrilled to have you with us. Get ready to stay updated with the latest trends and offers. | ||
</p> | ||
<a href="https://bitbox-in.netlify.app/" style="display: inline-block; padding: 12px 25px; margin-top: 20px; background-color: #4A90E2; color: white; font-size: 16px; font-weight: bold; text-decoration: none; border-radius: 5px;"> | ||
Explore More | ||
</a> | ||
<p style="margin-top: 30px;">Best Regards,<br>BitBox Team</p> | ||
</div> | ||
`, | ||
<!-- Footer --> | ||
<div style="background-color: #333; color: white; padding: 20px; text-align: center;"> | ||
<p style="margin: 0; font-size: 14px;">Best Regards, <br> <strong>BitBox Team</strong></p> | ||
<p style="margin: 0; font-size: 12px; color: #ccc;">Follow us on our social channels for more updates</p> | ||
</div> | ||
</div> | ||
`, | ||
attachments: [ | ||
{ | ||
filename: "bitbox", | ||
path: "Controllers/assests/bitboximage.png", | ||
cid: "welcomeImage", | ||
}, | ||
], | ||
}; | ||
|
||
// Send the confirmation email | ||
await transporter.sendMail(mailOptions); | ||
|
||
res.status(200).json({ message: "Subscription successful, confirmation email sent" }); | ||
res | ||
.status(200) | ||
.json({ message: "Subscription successful, confirmation email sent" }); | ||
} catch (error) { | ||
console.error("Error in subscribing to newsletter:", error.message); | ||
res.status(500).json({ message: error.message }); | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.