export default {
async email(message, env, ctx) {
try {
// Extract email data
const emailData = {
to: message.to,
from: message.from,
subject: message.headers.get('subject'),
timestamp: new Date().toISOString(),
headers: Object.fromEntries(message.headers),
// Get the email content
content: {
text: await message.text(),
html: await message.html()
}
};
// Forward email data to API
const response = await fetch("my site", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${env.API_KEY}`,
},
body: JSON.stringify(emailData)
});
if (!response.ok) {
console.error(`API request failed: ${response.status} ${response.statusText}`);
}
} catch (error) {
console.error("Error processing email:", error);
}
}
}
export default {
async email(message, env, ctx) {
try {
// Extract email data
const emailData = {
to: message.to,
from: message.from,
subject: message.headers.get('subject'),
timestamp: new Date().toISOString(),
headers: Object.fromEntries(message.headers),
// Get the email content
content: {
text: await message.text(),
html: await message.html()
}
};
// Forward email data to API
const response = await fetch("my site", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${env.API_KEY}`,
},
body: JSON.stringify(emailData)
});
if (!response.ok) {
console.error(`API request failed: ${response.status} ${response.statusText}`);
}
} catch (error) {
console.error("Error processing email:", error);
}
}
}