Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zou-yu committed Jul 26, 2024
0 parents commit 99b5f06
Show file tree
Hide file tree
Showing 21 changed files with 3,774 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/
dist/

.env

# IDE
.idea/

# Cloudflare
.wrangler/
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*

!dist/**
!package.json
!README.md
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) zou-yu

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.
58 changes: 58 additions & 0 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Worker Mailer

Worker Mailer 是一个运行在 Cloudflare Workers 上 SMTP 客户端库,通过 [Cloudflare TCP Sockets](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/) 实现且不依赖任何其他第三库。

## 特性

- 完全基于 Cloudflare Workers 运行时,无第三方依赖
- 完整的 Typescript 类型支持
- 支持纯文本和 HTML 邮件发送
- 支持 plain、login 和 CRAM-MD5 SMTP认证

## 快速开始

### 安装
```shell
npm i worker-mailer@beta
```


### 使用
`wranger.toml` 中配置
>compatibility_flags = ["nodejs_compat"]
```typescript
import { WorkerMailer } from 'worker-mailer'

const mailer = await WorkerMailer.connect({
credentials: {
username: '[email protected]',
password: 'password',
},
authType: 'plain',
host: 'smtp.acme.com',
port: 587,
secure: true,
})
await mailer.send({
from: { name: 'Bob', email: '[email protected]' },
// from: '[email protected]'
subject: 'Test email',
text: 'Plain message',
// html: '<p>HTML message</p>',
to: { name: 'Alice', email: '[email protected]' },
// to: [{ name: 'Alice', email: '[email protected]' }, { name: 'Sam', email: '[email protected]' }]
// to: '[email protected]'
})
```
For more API details, check out the TypeScript declaration file `dist/index.d.ts`

## 限制和已知的问题

- **端口限制:** Cloudflare Workers 禁用 25 端口的出站连接,您无法在 25 端口提交邮件,但是主流的 587 和 465 等端口是支持的

- **beta 阶段:** 该库目前处于 beta 阶段,正在快速开发中,可能会出现 bug,还有大量单元测试工作需完成

## 参与项目

欢迎您的贡献!如果在使用过程中遇到任何问题或有建议,请随时在 GitHub 仓库中提出 issue
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Worker Mailer

Worker Mailer is an SMTP client that runs on Cloudflare Workers. It leverages [Cloudflare TCP Sockets](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/) and doesn't rely on any other dependencies.

## Features

- Completely built on the Cloudflare Workers runtime with no other dependencies
- Full TypeScript type support
- Supports sending plain text and HTML emails
- Supports `plain`, `login`, and `CRAM-MD5` SMTP authentication

## Getting Started

### Installation

```shell
npm i worker-mailer@beta
```

### Usage

In your `wrangler.toml`, configure the following:
>compatibility_flags = ["nodejs_compat"]
```typescript
import { WorkerMailer } from 'worker-mailer'

const mailer = await WorkerMailer.connect({
credentials: {
username: '[email protected]',
password: 'password',
},
authType: 'plain',
host: 'smtp.acme.com',
port: 587,
secure: true,
})

await mailer.send({
from: { name: 'Bob', email: '[email protected]' },
// from: '[email protected]'
subject: 'Test email',
text: 'Plain message',
// html: '<p>HTML message</p>',
to: { name: 'Alice', email: '[email protected]' },
// to: [{ name: 'Alice', email: '[email protected]' }, { name: 'Sam', email: '[email protected]' }]
// to: '[email protected]'
})
```

For more API details, check out the TypeScript declaration file `dist/index.d.ts`.

## Limitations and Known Issues

- **Port Restrictions:** Cloudflare Workers cannot make outbound connections on port 25. You won't be able to send emails via port 25, but common ports like 587 and 465 are supported.
- **Beta Stage:** This library is currently in beta and is under rapid development. There might be bugs, and there's still a lot of unit testing to be done.

## Contributing

We welcome your contributions! If you encounter any issues or have suggestions while using this library, feel free to open an issue on our GitHub repository.
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "worker-mailer",
"version": "0.0.4-beta.0",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"keywords": [
"cloudflare",
"worker",
"cloudflare-worker",
"email",
"smtp"
],
"author": "zou-yu",
"repository": {
"url": "https://github.com/zou-yu/worker-mailer"
},
"homepage": "https://github.com/zou-yu/worker-mailer",
"scripts": {
"build": "tsup",
"test": "vitest",
"format": "prettier '**/*.{json,ts,js,cjs,mjs}' --write --ignore-path .gitignore"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.4.5",
"@cloudflare/workers-types": "^4.20240722.0",
"@types/node": "^20.14.12",
"prettier": "^3.3.3",
"tsup": "^8.2.3",
"typescript": "^5.5.2",
"vitest": "1.5.0",
"wrangler": "^3.60.3"
}
}
Loading

0 comments on commit 99b5f06

Please sign in to comment.