Email triggers provide a unique email address for your val. When Val Town receives an email at that address, it triggers the corresponding file within the val with the email as its first argument.
Some common examples include:
- Automatically forwarding emails
- Posting support team emails to Discord / Slack
Type Signature
Files triggered by Email receive an argument called Email
that represents the email that was sent. Here’s an example:
export async function emailValHandler(email: Email) { console.log("Email received!", email.from, email.subject, email.text); for (const file of email.attachments) { console.log(`Filename: ${file.name}`) console.log(`Content Type: ${file.type}`) console.log(`Content: ${await file.text()}`) };}
The Email
type has this shape:
interface Email { from: string; to: string[]; cc: string | string[] | undefined; bcc: string | string[] | undefined; subject: string | undefined; text: string | undefined; html: string | undefined; attachments: File[];}
Example
This Email trigger forwards any email it receives to me. Try it out by sending an email to stevekrouse.forwarder@valtown.email
.