Public
std
email
Script
Email - Docs ↗ Send emails with std/email . You can only send emails to yourself if you're on Val Town Free. If you're on Val Town Pro , you can email anyone. Want to receive emails instead? Create an email handler val Basic usage import { email } from "https://esm.town/v/std/email";
await email({ subject: "New Ink & Switch Post!", text: "https://www.inkandswitch.com/embark/" }); subject The email subject line. It defaults to Message from @your_username on Val Town . to , cc , and bcc By default, the to field is set to the owner of the Val Town account that calls it. If you have Val Town Pro, you can send emails to anyone via the to , cc , and bcc fields. If you don't have Val Town Pro, you can only send emails to yourself, so leave those fields blank. from The from is limited to a few options: It defaults to notifications@val.town if you don't specify it. If you do specify it, it must be of the form: your_username.valname@valtown.email . replyTo replyTo accepts a string email or an object with strings for email and name (optional). This can be useful if you are sending emails to others with Val Town Pro. import { email } from "https://esm.town/v/std/email";
await email({
to: "someone_else@example.com",
from: "your_username.valname@valtown.email",
replyTo: "your_email@example.com",
text: "these pretzels are making me thirsty",
}); Attachments You can attach files to your emails by using the attachments field.
Attachments need to be Base64 encoded,
which is what the btoa
method is doing in this example: import { email } from "https://esm.town/v/std/email";
export const stdEmailAttachmentExample = email({
attachments: [
{
content: btoa("hello attachments!"),
filename: "test.txt",
type: "text",
disposition: "attachment",
},
],
}); Here's an example sending a PDF . Headers You can set custom headers in emails that you send: import { email } from "https://esm.town/v/std/email?v=13"
console.log(
await email({
text: "Hi",
headers: {
"X-Custom-Header": "xxx",
},
}),
) This is also documented in our REST API , and supported in the SDK . 📝 Edit docs
7
postpostscript
multiFormat
Script
multiFormat: easily create outputs of multiple formats (e.g. text/html for Email) using tagged templates Examples import { format } from "https://esm.town/v/postpostscript/multiFormat";
console.log(format.Plain`
${format.Heading1`Some Heading`}
Lorem ipsum dolor ${format.Strong`sit`} amet
`); {
"text": "\nSome Heading\n\nLorem ipsum dolor sit amet\n",
"html": "\n<br><h1>Some Heading</h1>\n<br>\n<br>Lorem ipsum dolor <strong>sit</strong> amet\n<br>"
} Create Your Own Formatters import { createFormatMethod, wrapHTMLTag, type MultiFormatWithHTML } from "https://esm.town/v/postpostscript/multiFormat";
export const Red = createFormatMethod<MultiFormatWithHTML>((value) => {
return wrapHTMLTag("span", value, {
style: "color: red;",
});
});
console.log(Red`red text!`) {
"text": "red text!",
"html": "<span style=\"color: red;\">red text!</span>"
} Sanitization Text is automatically sanitized when converted to HTML: console.log(format.Trim`
${format.Heading1`Some Heading`}
<script>alert(1)</script>
`.html.toString()) <h1>Some Heading</h1>
<br>
<br><script>alert(1)</script>
0
postpostscript
jwks
HTTP
jwks Required Setup Fork this val Set JWKS Environment Variables Go to https://postpostscript-generatejwksenv.web.val.run/?prefix=JWKS Follow the steps there with the prefix "JWKS" If you want to set the keys up manually, set up env vars JWKS_PRIVATE and JWKS_PUBLIC as JWKS with the algorithm RS512 in this format: {
"keys": [
{ ... }
]
}
0
postpostscript-authid.web.val.run
Updated: March 3, 2024