What is the name of the domain?
What is the issue you’re encountering
It shows error “Uncaught (in promise) TypeError: Too many redirects” in console
What are the steps to reproduce the issue?
Here is my piece of code:
export default {
async email(message, env, ctx) {
// Extract the sender and subject
const sender = message.from;
const headers = Object.fromEntries(message.headers);
// Extract raw email content
const rawEmail = await new Response(message.raw).text();
// Prepare payload for the API
const payload = JSON.stringify({
subject: headers.subject,
name: sender,
email: sender,
message: rawEmail,
});
// API Call with Basic Authentication
const apiResponse = await fetch("https://example.com/api/inboxes/", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic secret",
},
body: payload,
});
// Check API response
if (!apiResponse.ok) {
console.error("API Call Failed. Status:", apiResponse.status);
const errorText = await apiResponse.text();
console.error("Error Response Body:", errorText);
message.setReject("Failed to process email.");
} else {
console.log("Email processed and forwarded to API.");
}
},
};