Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added news letter api #387

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions server/Controllers/OtherController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
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.