Email worker forwarding emails twice?

hey yall. im attempting to set up a catch-all worker to forward "+" emails to their respective custom addresses. for example i have the custom address [email protected] forwarding to [email protected]. i wrote a worker to catch addresses like [email protected] and forward said email to [email protected]. the good news is it works! but maybe a little too much. all the emails are coming in twice at the same time. not sure what im doing wrong or if i have my setup weird. any ideas? note the emails used here are verified and i have both the catchall and my custom emails online.
export default {
async email(message, env, ctx) {
// Extract the local part and domain of the email address
const [localPart, domain] = message.to.split('@');

// List of existing custom addresses (anonymized)
const customAddresses = {
'alias1': '[email protected]',
'alias2': '[email protected]',
'support': '[email protected]',
};

// Only proceed if the local part contains a '+'
if (localPart.includes('+')) {
// Extract the base address (portion before the '+')
const baseAddress = localPart.split('+')[0];

// Check if the base address is in the custom addresses list
const destination = customAddresses[baseAddress];
if (destination) {
// Forward to the appropriate destination
await message.forward(destination);
} else {
// Reject if base address is not recognized
message.setReject(`No such address: ${baseAddress}@${domain}`);
}
}
}
}
export default {
async email(message, env, ctx) {
// Extract the local part and domain of the email address
const [localPart, domain] = message.to.split('@');

// List of existing custom addresses (anonymized)
const customAddresses = {
'alias1': '[email protected]',
'alias2': '[email protected]',
'support': '[email protected]',
};

// Only proceed if the local part contains a '+'
if (localPart.includes('+')) {
// Extract the base address (portion before the '+')
const baseAddress = localPart.split('+')[0];

// Check if the base address is in the custom addresses list
const destination = customAddresses[baseAddress];
if (destination) {
// Forward to the appropriate destination
await message.forward(destination);
} else {
// Reject if base address is not recognized
message.setReject(`No such address: ${baseAddress}@${domain}`);
}
}
}
}
3 Replies
cinstitute
cinstituteOP2mo ago
interestingly inside my dashboard these emails are showing as dropped even though they went through?
No description
cinstitute
cinstituteOP2mo ago
this is how it looks on my end
No description
Jerry Shi
Jerry Shi2mo ago
Yes. Somehow the system shows the status as "dropped" if the worker successfully has forwarded the email. I was confused, too, and spent quite a bit time to troubleshoot. It is not clear how the worker can return a different state, e.g., rejected and forwarded.
Want results from more Discord servers?
Add your server