Files
AIGC/demo/TENCENT_SES_CONFIG.md
AIGC Developer a13ff70055 feat: 实现邮箱验证码登录和腾讯云SES集成
- 实现邮箱验证码登录功能,支持自动注册新用户
- 修复验证码生成逻辑,确保前后端验证码一致
- 添加腾讯云SES webhook回调接口,支持6种邮件事件
- 配置ngrok内网穿透支持,允许外部访问
- 优化登录页面UI,采用全屏背景和居中布局
- 清理调试代码和未使用的导入
- 添加完整的配置文档和测试脚本
2025-10-23 17:50:12 +08:00

192 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 腾讯云邮件推送服务SES配置指南
## 🎯 配置目标
配置腾讯云SES服务实现真实的邮件验证码发送功能。
## 📋 详细配置步骤
### 1. 开通腾讯云SES服务
#### 1.1 登录腾讯云控制台
- 访问https://console.cloud.tencent.com/
- 使用您的腾讯云账号登录
#### 1.2 开通邮件推送服务
1. 在控制台搜索"邮件推送"或"SES"
2. 进入邮件推送控制台
3. 点击"立即开通"
4. 完成实名认证(如需要)
### 2. 获取API密钥
#### 2.1 创建API密钥
1. 控制台 → 访问管理 → API密钥管理
2. 点击"新建密钥"
3. 记录以下信息:
- **SecretId**:如 `AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
- **SecretKey**:如 `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
### 3. 配置发件人邮箱
#### 3.1 添加发件人
1. 邮件推送控制台 → 发件人管理
2. 点击"添加发件人"
3. 填写信息:
- **发件人邮箱**:如 `noreply@yourdomain.com`
- **发件人名称**:如 `AIGC Demo`
4. 点击"确定"
#### 3.2 验证发件人
1. 系统会向您的邮箱发送验证邮件
2. 点击邮件中的验证链接
3. 验证成功后,发件人状态变为"已验证"
### 4. 修改配置文件
编辑 `src/main/resources/application-tencent.properties`
```properties
# 腾讯云配置
tencent.cloud.secret-id=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
tencent.cloud.secret-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# 邮件推送服务配置
tencent.cloud.ses.region=ap-beijing
tencent.cloud.ses.from-email=noreply@yourdomain.com
tencent.cloud.ses.from-name=AIGC Demo
tencent.cloud.ses.template-id=your-email-template-id
```
### 5. 配置邮件模板(可选)
#### 5.1 创建邮件模板
1. 邮件推送控制台 → 邮件模板
2. 点击"创建模板"
3. 选择"验证码模板"
4. 填写模板内容:
**模板名称**:验证码邮件
**模板内容**
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>验证码</title>
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
<div style="max-width: 600px; margin: 0 auto; padding: 20px;">
<h2 style="color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;">
验证码
</h2>
<p>您好!</p>
<p>您的验证码是:<strong style="color: #e74c3c; font-size: 24px;">{{code}}</strong></p>
<p>请在5分钟内输入如非本人操作请忽略此邮件。</p>
<hr style="border: none; border-top: 1px solid #eee; margin: 20px 0;">
<p style="color: #7f8c8d; font-size: 12px;">
此邮件由系统自动发送,请勿回复。
</p>
</div>
</body>
</html>
```
#### 5.2 获取模板ID
- 模板创建成功后记录模板ID
- 更新配置文件中的 `tencent.cloud.ses.template-id`
### 6. 启用腾讯云配置
#### 6.1 修改主配置文件
编辑 `src/main/resources/application.properties`
```properties
# 启用腾讯云配置
spring.profiles.active=tencent
```
#### 6.2 修改验证码服务
取消注释 `VerificationCodeService.java` 中的腾讯云相关代码:
```java
@Autowired
private TencentCloudConfig tencentCloudConfig;
```
### 7. 测试配置
#### 7.1 启动应用
```bash
mvn spring-boot:run
```
#### 7.2 测试发送验证码
```bash
curl -X POST http://api.yourdomain.com:8080/api/verification/email/send \
-H "Content-Type: application/json" \
-d '{"email": "your-test-email@example.com"}'
```
#### 7.3 检查邮件
- 查看您的邮箱是否收到验证码邮件
- 检查应用日志中的发送状态
## 🔧 配置参数说明
| 参数 | 说明 | 示例值 |
|------|------|--------|
| `secret-id` | 腾讯云API密钥ID | `AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
| `secret-key` | 腾讯云API密钥 | `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
| `ses.region` | 服务地域 | `ap-beijing` |
| `ses.from-email` | 发件人邮箱 | `noreply@yourdomain.com` |
| `ses.from-name` | 发件人名称 | `AIGC Demo` |
| `ses.template-id` | 邮件模板ID | `123456` |
## 🚨 注意事项
### 安全提醒
1. **保护API密钥**不要将SecretId和SecretKey提交到代码仓库
2. **使用环境变量**:生产环境建议使用环境变量存储敏感信息
3. **限制权限**为API密钥设置最小权限
### 费用说明
1. **免费额度**腾讯云SES通常有免费额度
2. **计费方式**:按发送量计费
3. **成本控制**:设置发送频率限制
### 限制说明
1. **发送频率**同一邮箱60秒内只能发送一次
2. **验证码有效期**5分钟
3. **每日限额**:根据您的套餐设置
## 🔍 故障排除
### 常见问题
#### 1. 邮件发送失败
- 检查API密钥是否正确
- 检查发件人是否已验证
- 检查网络连接
#### 2. 验证码收不到
- 检查垃圾邮件文件夹
- 检查邮箱地址是否正确
- 检查发送频率限制
#### 3. 配置不生效
- 检查配置文件路径
- 检查profile配置
- 重启应用
### 日志查看
```bash
# 查看应用日志
tail -f logs/application.log | grep "验证码"
```
## 📞 技术支持
- 腾讯云SES文档https://cloud.tencent.com/document/product/1288
- 腾讯云技术支持https://cloud.tencent.com/about/connect