Readme

Val Town Company *@val.town Email Routing

This val forwards emails to addresses that don't exist to all of us at Val Town. For example, this forwards feedback@val.town to all of us. We achieve this by forwarding emails to this email handler, and this email handler forwards them along.

Screenshot 2024-02-16 at 10.03.59.png

To accomplish this without Val Town would require setting up a Google Group. I prefer doing it in code. Over time we will have more complex routing here.

This doesn't support attachments, sadly, until email handlers support attachments.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { email } from "https://esm.town/v/std/email?v=11";
import { parseAddressList } from "https://esm.town/v/std/parse_email?v=6";
import { parse } from "https://esm.town/v/stevekrouse/parseEmail";
import addressparser from "npm:addressparser";
const team = [
{ name: "Steve Krouse", email: "steve@val.town" },
{ name: "Tom MacWright", email: "tom@val.town" },
{ name: "Max McDonnell", email: "max@val.town" },
{ name: "Brent Jackson", email: "jackson@val.town" },
];
const [steve, tom, andre] = team;
export default async function(e: Email) {
console.log(JSON.stringify(e, null, 2));
const [to, cc, bcc, from] = [e.to, e.cc, e.cc, e.from].map(parse);
const recipients = [...to, ...cc, ...bcc];
// if you send an email to more than one @val.town 404 email, this will pick the first
// but this val will likely get triggered for each @val.town 404 email listed
// we should probably fix that eventually...
const me = recipients.find(x => x.email.includes("@val.town"));
const myName = me.name.length ? me.name : me.email.replace("@val.town", "");
const replyTo = [...recipients, ...from]
.filter(x => !x.email.includes("@val.town") && !x.email.includes("@valtown.email"));
const forwardTo = me.email.includes("krouse") ? [steve] : team;
await email({
from: { name: `Val Town ${myName}`, email: "stevekrouse.company@valtown.email" },
replyTo,
to: forwardTo,
subject: e.subject,
text: e.text,
html: e.html,
// TODO attachments: e..attachments
});
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.