Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
willin authored Aug 21, 2024
0 parents commit 74b12ff
Show file tree
Hide file tree
Showing 16 changed files with 726 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Only For Github Actions
CLOUDFLARE_API_TOKEN="xxx"
CLOUDFLARE_ACCOUNT_ID="xxx"

### Resend 邮件发送服务,可自行注册免费发送
### Resend mail sending service, you can register for free sending
RESEND_API_KEY="re_xxxx"
### 发送邮件的用户名
### The username of the email sent
EMAIL_USERNAME="No-Reply <no-reply@system.example.com>"
### 发送测试邮件接收的地址
### Address to receive test emails
TEST_EMAIL_ADDRESS="your@email.com"
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://editorconfig.org/
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[Makefile]
indent_style = tab
# http://editorconfig.org
root = true
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy

on:
push:
branches:
- main
paths-ignore:
- '**.md'
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
RESEND_API_KEY
EMAIL_USERNAME
TEST_EMAIL_ADDRESS
env:
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
TEST_EMAIL_ADDRESS: ${{ secrets.TEST_EMAIL_ADDRESS }}
172 changes: 172 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars
.wrangler/
7 changes: 7 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tabWidth: 2
semi: true
singleQuote: true
jsxSingleQuote: true
trailingComma: none
printWidth: 120
bracketSameLine: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Willin Wang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Resend Cloudflare Worker Service

[中文版](./README.zh-cn.md) / [English](./README.md)

## Prepare

1. `Use this template` to fork this repository to create your project
2. Set `Actions Secrets` in the project `Settings`, add the following environment variables:

```bash
### Only For Github Actions
CLOUDFLARE_ACCOUNT_ID="xxx"
CLOUDFLARE_API_TOKEN="xxx"

### Resend mail sending service, you can register for free sending
RESEND_API_KEY="re_xxxx"
### The username of the email sent
EMAIL_USERNAME="No-Reply <no-reply@system.example.com>"
### Address to receive test emails
TEST_EMAIL_ADDRESS="your@email.com"
```

## Use in Worker / Pages

Modify the `wrangler.toml` configuration in the project, add:

```toml
[[services]]
binding = "RESEND"
service = "email-sender-worker"
```

Then use in the code:

```ts
await ctx.env.RESEND.sendEmail({
to: ['address@example.com'], // or just a string
subject: 'Hello, World!',
html: '<h1>Hello, World!</h1>'
}); // returns b
```

Where the parameter of `sendEmail` is of type `SendEmailOptions`:

```ts
type SendEmailProps = {
to: string | string[];
subject: string;
html: string;
};
```

## Local Development

```bash
# npm, yarn, or pnpm
bun install
bun run dev
```

Then visit <http://localhost:8787>, a test email will be sent to `TEST_EMAIL_ADDRESS` mailbox.

## Sponsor

Donation ways:

- Github: <https://github.com/sponsors/willin> [![github](https://img.shields.io/github/followers/willin.svg?style=social&label=Followers)](https://github.com/willin)
- Alipay or Wechat Pay: [QRCode](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)
- ETH: `0x6D877f96198E55085CEb56097B099cc7bb814263`

## License

MIT
Loading

0 comments on commit 74b12ff

Please sign in to comment.