Skip to content

Commit 18d56fa

Browse files
committed
docs: update email-server subscription headers
1 parent c18e992 commit 18d56fa

File tree

1 file changed

+61
-28
lines changed

1 file changed

+61
-28
lines changed

src/pages/email-server/how-tos/set-subscription-header.mdx

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,30 @@ async function sendEmail() {
7171
to: "someguy@example.com",
7272
subject: "Test Email",
7373
text: "Hello, this is a test email sent from Node.js using your SMTP server.",
74-
headers: {
75-
"List-Subscribe": "<http://www.example.com/subscribe> ",
76-
"List-Unsubscribe": "<http://www.example.com/unsubscribe>"
74+
list: {
75+
unsubscribe: {
76+
url: 'http://example.com',
77+
comment: 'Unsubscribe'
78+
},
79+
subscribe: [
80+
'<mailto:admin@example.com?subject=subscribe>',
81+
{
82+
url: 'http://example.com',
83+
comment: 'Subscribe'
84+
}
85+
]
7786
}
7887
};
7988
80-
let info = await transporter.sendMail(mailOptions);
81-
console.log("Email sent: " + info.messageId);
89+
try {
90+
let info = await transporter.sendMail(mailOptions);
91+
console.log("Email sent: " + info.messageId);
92+
} catch (error) {
93+
console.error("Error sending email:", error);
94+
}
8295
}
8396
84-
sendEmail().catch(console.error);
97+
sendEmail();
8598
`}
8699
</Highlight>
87100
</div>
@@ -92,29 +105,49 @@ sendEmail().catch(console.error);
92105
{`import nodemailer from "nodemailer";
93106
94107
export default async function handler(req, res) {
95-
let transporter = nodemailer.createTransport({
96-
host: "smtp.c1.liara.email",
97-
port: 465,
98-
secure: true,
99-
auth: {
100-
user: "your-smtp-user",
101-
pass: "your-smtp-pass"
102-
}
103-
});
108+
if (req.method !== "POST") {
109+
return res.status(405).json({ error: "Method Not Allowed" });
110+
}
104111
105-
let mailOptions = {
106-
from: "info@example.com",
107-
to: "someguy@example.com",
108-
subject: "Test Email",
109-
text: "Hello, this is a test email sent from Next.js.",
110-
headers: {
111-
"List-Subscribe": "<http://www.example.com/subscribe>",
112-
"List-Unsubscribe": "<http://www.example.com/unsubscribe>"
113-
}
114-
};
112+
try {
113+
let transporter = nodemailer.createTransport({
114+
host: "smtp.c1.liara.email",
115+
port: 465,
116+
secure: true,
117+
auth: {
118+
user: "your-smtp-user",
119+
pass: "your-smtp-pass"
120+
}
121+
});
122+
123+
let mailOptions = {
124+
from: "info@example.com",
125+
to: "someguy@example.com",
126+
subject: "Test Email",
127+
text: "Hello, this is a test email sent from Next.js.",
128+
list: {
129+
subscribe: [
130+
'<mailto:admin@example.com?subject=subscribe>',
131+
{
132+
url: "http://www.example.com/subscribe",
133+
comment: "Subscribe"
134+
}
135+
],
136+
unsubscribe: {
137+
url: "http://www.example.com/unsubscribe",
138+
comment: "Unsubscribe"
139+
}
140+
}
141+
};
142+
143+
let info = await transporter.sendMail(mailOptions);
144+
console.log("Email sent:", info.messageId);
115145
116-
await transporter.sendMail(mailOptions);
117-
res.status(200).json({ message: "Email sent successfully!" });
146+
return res.status(200).json({ message: "Email sent successfully!" });
147+
} catch (error) {
148+
console.error("Error sending email:", error);
149+
return res.status(500).json({ error: "Failed to send email." });
150+
}
118151
}
119152
`}
120153
</Highlight>
@@ -373,7 +406,7 @@ send_email()
373406
<p>
374407
در قطعه کدهای فوق، به‌جای <Important>http://www.example.com/subscribe</Important> و <Important>http://www.example.com/unsubscribe</Important>، آدرس‌های مربوط به صفحه‌های Subscribe و Unsubscribe خود را قرار دهید.
375408
همچنین، عبارت <Important>(Click here to subscribe/unsubscribe to our mailing list)</Important> که یک نوع comment می‌باشد را، می‌توانید تغییر دهید. البته
376-
این نوع comment در NodeJS و NextJS قابل استفاده، نیست.
409+
این نوع comment در NodeJS و NextJS در فیلد <Important>comment</Important>، قرار می‌گیرد.
377410
</p>
378411
</Alert>
379412

0 commit comments

Comments
 (0)