Public
Email
Readme

Newsly

inspired by https://kill-the-newsletter.com/

  • copy your email into a newsletter like substack
  • read the newsletter here / store them into valtown
  • you can set it so you can chat with it or send you alerts or whatever idk
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* This val creates an email storage system using SQLite.
* It stores each email sent through the 'newsly' function into a SQLite database.
* The email address of the sender is used as the key.
* We'll use the sqlite module for database operations and the email module for sending emails.
*/
// import { email } from "https://esm.town/v/std/email?v=11";
export async function newsly2(e: {
from: string;
to: string[];
subject: string;
text: string;
html: string;
}) {
console.log("email:", JSON.stringify(e));
// Store the email in the database
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
// Create the table if it doesn't exist
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS ${KEY}_newslies (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_email TEXT NOT NULL,
to_emails TEXT NOT NULL,
subject TEXT NOT NULL,
text_content TEXT NOT NULL,
html_content TEXT NOT NULL,
sent_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
await sqlite.execute(`
INSERT INTO ${KEY}_newslies (from_email, to_emails, subject, text_content, html_content)
VALUES (?, ?, ?, ?, ?)
`, [e.from, JSON.stringify(e.to), e.subject, e.text, e.html]);
}
const css = `
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #2c3e50;
}
p {
margin-bottom: 10px;
}
a {
color: #3498db;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
`;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 23, 2024