title:
Email
description:
A kind of val that is able to receive emails sent to it

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

Vals can send email, too! Using the email function in the standard library.

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.

Custom email address

Similar to HTTP endpoints, you can set a custom email address by clicking on the Email trigger and selecting Custom email address.

You can choose any available email address ending in @valtown.email.

custom-email-add.png

Limitations

Note: Email size limit

The total size of inbound emails, including attachments, must be less than 30MB.

Email triggers are powered internally by Sendgrid Inbound Parse.