Skip to content

Commit

Permalink
Add social share to daily email
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed0saber committed May 30, 2024
1 parent 3f0e3c4 commit fc29f6e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
73 changes: 72 additions & 1 deletion app/api/utils/email/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const sendDailyEmail = async ({ subscribers } = {}) => {
const randomVerse = getRandomItemFromArray(verses)
const stringifiedEmails = subscribers.map(subscriber => subscriber.email).join(", ")

const shareText = `الآية ${randomVerse.ayah} من سورة ${randomVerse.sora.trim()}
%0A{ ${randomVerse.content.trim()} }%0A%0A
للمزيد قم بزيارة الرابط التالي:
%0A${encodeURI("https://quran-mailer.vercel.app")}`

const html = `
<div dir="rtl" style="background-color:#F7F7F7;padding:12px;font-family:system-ui;">
<h2
Expand All @@ -59,6 +64,54 @@ const sendDailyEmail = async ({ subscribers } = {}) => {
${randomVerse.content}
</p>
</div>
<p
style="color:#323232;
font-size:18px;
margin:12px 0;"
>
شارك هذه الآية عبر المنصات التالية ولك أجرٌ على كل من يقرأها بإذن الله.
</p>
<div>
<a
style="color:#0000;"
target="_blank"
href="https://api.whatsapp.com/send?text=${shareText}"
title="Share on WhatsApp"
>
<img
src="cid:01"
alt="WhatsApp Icon"
width="48"
height="48"
/>
</a>
<a
style="color:#0000;"
target="_blank"
href="https://t.me/share/url?url=${encodeURI("https://quran-mailer.vercel.app")}&text=%0A${shareText}"
title="Share on Telegram"
>
<img
src="cid:02"
alt="Telegram Icon"
width="48"
height="48"
/>
</a>
<a
style="color:#0000;"
target="_blank"
href="https://twitter.com/intent/tweet?text=${shareText}"
title="Share on Twitter"
>
<img
src="cid:03"
alt="Twitter Icon"
width="48"
height="48"
/>
</a>
</div>
${randomVerse.tafseer ?
`<div>
<h2
Expand Down Expand Up @@ -108,7 +161,25 @@ const sendDailyEmail = async ({ subscribers } = {}) => {
</div>
`

return sendEmail({ to: stringifiedEmails, subject: "Daily Quran Verse", html })
const attachments = [
{
filename: "whatsapp.png",
path: "./public/social-icons/whatsapp.png",
cid: "01"
},
{
filename: "telegram.png",
path: "./public/social-icons/telegram.png",
cid: "02"
},
{
filename: "twitter.png",
path: "./public/social-icons/twitter.png",
cid: "03"
},
]

return sendEmail({ to: stringifiedEmails, subject: "Daily Quran Verse", html, attachments })
}

export { sendContactEmail, sendVerificationEmail, sendDailyEmail }
5 changes: 3 additions & 2 deletions app/api/utils/email/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const sendEmail = async ({ to = process.env.GMAIL_USER, subject, html } = {}) => {
const sendEmail = async ({ to = process.env.GMAIL_USER, subject, html, attachments } = {}) => {
const mailTransporter = require('../../../../lib/nodemailer');
const mailOptions = {
from: process.env.GMAIL_USER,
to,
subject,
html
html,
attachments
}

return new Promise((resolve, reject) => {
Expand Down
Binary file added public/social-icons/telegram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/social-icons/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/social-icons/whatsapp.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 fc29f6e

Please sign in to comment.