Skip to content

Commit

Permalink
added news letter api
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSharma72 committed Nov 5, 2024
1 parent d18201b commit 6c0dd32
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions server/Controllers/OtherController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,69 @@ const subscribeNewsletter = async (req, res) => {
await newSubscriber.save();

// Configure the transporter
// const transporter = nodemailer.createTransport({
// service: "gmail",
// auth: {
// user: process.env.EMAIL_USER, // Use environment variables in production
// pass: process.env.EMAIL_PASS,
// },
// });
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: "[email protected]", // Your email
pass: "kmepakzcabvztekd", // Your email password
},
});

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 });
Expand Down
Binary file added server/Controllers/assests/bitboximage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c0dd32

Please sign in to comment.