This commit is contained in:
2025-02-27 17:10:33 +08:00
parent d3a3e1918c
commit d61028a104
20 changed files with 4274 additions and 96 deletions

87
api/README.md Normal file
View File

@@ -0,0 +1,87 @@
# 邮件发送API
这是一个简单的Express后端服务用于处理联系表单的邮件发送功能。
## 安装
```bash
cd api
npm install
```
## 配置
编辑 `.env` 文件,填入您的邮箱配置:
```
# 服务器配置
PORT=3001
# 邮件配置
EMAIL_SERVICE=163 # 邮件服务提供商
EMAIL_HOST=smtp.163.com # SMTP服务器地址
EMAIL_PORT=465 # SMTP端口
EMAIL_SECURE=true # 是否使用SSL/TLS
EMAIL_USER=your-email@163.com # 发送邮件的邮箱地址
EMAIL_PASS=your-password-or-app-password # 邮箱密码或授权码
EMAIL_RECIPIENT=recipient@example.com # 接收邮件的邮箱地址(可选默认与EMAIL_USER相同)
```
对于大部分邮箱服务商,您需要生成专门的"应用密码"或"授权码",而不是使用登录密码。例如:
- 对于163邮箱您需要在邮箱设置中开启SMTP服务并获取授权码
- 对于Gmail您需要开启两步验证并生成应用专用密码
## 运行
```bash
# 开发模式(自动重启)
npm run dev
# 生产模式
npm start
```
服务器将在 http://localhost:3001 上运行。
## API端点
### 发送邮件
```
POST /api/send-email
```
请求体示例:
```json
{
"name": "张三",
"email": "zhangsan@example.com",
"subject": "合作咨询",
"message": "我对您的项目很感兴趣,希望能进一步了解。"
}
```
成功响应:
```json
{
"success": true,
"message": "邮件已成功发送"
}
```
### 测试API
```
GET /api/test
```
响应示例:
```json
{
"message": "API服务器运行正常"
}
```