Skip to content

Commit e4b487a

Browse files
committed
docs: confirm email example
1 parent 6039c22 commit e4b487a

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"trailingComma": "all",
66
"arrowParens": "always",
77
"bracketSpacing": true
8-
}
8+
}

examples/confirm_email/index.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import 'dotenv/config'
2+
import {
3+
Header,
4+
Footer,
5+
Content,
6+
Email,
7+
EmailAddress,
8+
Templateless,
9+
SocialItem,
10+
Service,
11+
} from 'templateless-js'
12+
13+
const sendEmail = async () => {
14+
let api_key = process.env.TEMPLATELESS_API_KEY
15+
if (!api_key) {
16+
console.error('Set TEMPLATELESS_API_KEY to your Templateless API key')
17+
return
18+
}
19+
20+
let email_address = process.env.TEMPLATELESS_EMAIL_ADDRESS
21+
if (!email_address) {
22+
console.error('Set TEMPLATELESS_EMAIL_ADDRESS to your own email address')
23+
return
24+
}
25+
26+
const header = Header.builder().text('# ExampleApp').build()
27+
28+
const footer = Footer.builder()
29+
.socials([
30+
new SocialItem(Service.Twitter, 'ExampleApp'),
31+
new SocialItem(Service.Github, 'ExampleApp'),
32+
])
33+
.link('Unsubscribe', 'https://example.com/unsubscribe?id=123')
34+
.build()
35+
36+
const content = Content.builder()
37+
.header(header)
38+
.text('Hello world')
39+
.footer(footer)
40+
.build()
41+
42+
const email = Email.builder()
43+
.to(new EmailAddress(email_address))
44+
.subject('Confirm your email')
45+
.content(content)
46+
.build()
47+
48+
const templateless = new Templateless(api_key)
49+
const result = await templateless.send(email)
50+
51+
console.log(result)
52+
}
53+
54+
sendEmail()

examples/confirm_email/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "templateless-js-example-confirm-email",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "node index.js"
8+
},
9+
"dependencies": {
10+
"templateless-js": "file:../..",
11+
"dotenv": "16.4.1"
12+
}
13+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"typings": "dist/index.d.ts",
2323
"scripts": {
2424
"lint": "eslint '**/*.{js,ts,json}' --fix",
25-
"format": "prettier --write 'src/**/*.{js,ts,json}'",
25+
"format": "prettier --write '**/*.{js,ts,json}'",
2626
"test": "jest --passWithNoTests",
2727
"build": "rollup -c --bundleConfigAsCjs",
2828
"all": "npm run format && npm run lint && npm test && npm run build"

0 commit comments

Comments
 (0)