Email Provider compatible with cloudflare pages

Hi Guys Recently i tried to host my sveltekit in cloudflare pages with sendgrid, however there is a problem with their library when i tried to deploy it in cloudlfare
00:56:41.846 ✘ [ERROR] Could not resolve "fs"
00:56:41.846
00:56:41.846 node_modules/@sendgrid/helpers/classes/attachment.js:9:19:
00:56:41.846 9 │ const fs = require('fs');
00:56:41.846 ╵ ~~~~
00:56:41.846 ✘ [ERROR] Could not resolve "fs"
00:56:41.846
00:56:41.846 node_modules/@sendgrid/helpers/classes/attachment.js:9:19:
00:56:41.846 9 │ const fs = require('fs');
00:56:41.846 ╵ ~~~~
any other recommendation for email service? i tried to enable nodejs_compat
No description
2 Replies
Cyb3r-Jak3
Cyb3r-Jak38mo ago
I don't think you can use their library. It relies on the fs package which isn't avaiable on the Cloudflare runtime
Adi
Adi8mo ago
You'll need to use their REST API. Something like this
const response = await fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${env.SENDGRID_API_KEY}`,
},
body: JSON.stringify({
personalizations: [{ to: [{ email: options.to }], subject: options.subject }],
from: { email: 'from-email' },
reply_to: { email: 'to-email' },
content: [
{
type: 'text/plain',
value: 'YOUR_EMAIL_TEXT',
},
{
type: 'text/html',
value: 'YOUR_EMAIL_HTML',
},
],
mail_settings: { sandbox_mode: false // as-needed } },
}),
});
const response = await fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${env.SENDGRID_API_KEY}`,
},
body: JSON.stringify({
personalizations: [{ to: [{ email: options.to }], subject: options.subject }],
from: { email: 'from-email' },
reply_to: { email: 'to-email' },
content: [
{
type: 'text/plain',
value: 'YOUR_EMAIL_TEXT',
},
{
type: 'text/html',
value: 'YOUR_EMAIL_HTML',
},
],
mail_settings: { sandbox_mode: false // as-needed } },
}),
});
Want results from more Discord servers?
Add your server