5b4774e9c1
- 新增完整的Go客户端库实现,支持邮件服务器API的各种操作 - 实现账户管理、签名管理、邮件发送、审计、配额、通道等功能模块 - 提供ServiceAuth和AppAuth两种认证模式的客户端 - 添加详细的README文档,包含安装指南和使用示例 - 配置.gitignore文件以忽略构建产物和开发工具配置 - 支持分页查询、错误处理和客户端选项配置
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package emailcli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// SendMail sends an email. Requires an AppClient (X-App-Key/X-App-Secret auth).
|
|
func (c *Client) SendMail(ctx context.Context, req SendMailReq) (*SendMailResp, error) {
|
|
return post[*SendMailResp](c, ctx, "/api/v1/mail/send", req)
|
|
}
|
|
|
|
// ListMailLogs lists mail log records with filters (ServiceAuth).
|
|
func (c *Client) ListMailLogs(ctx context.Context, q MailLogListQuery) (*PaginationResult[MailLog], error) {
|
|
params := mergeParams(paginationParams(q.PaginationQuery), map[string]interface{}{
|
|
"user_id": q.UserID,
|
|
"account_id": q.AccountID,
|
|
"status": q.Status,
|
|
"start_date": q.StartDate,
|
|
"end_date": q.EndDate,
|
|
"to": q.To,
|
|
"keyword": q.Keyword,
|
|
})
|
|
return get[*PaginationResult[MailLog]](c, ctx, "/api/v1/mail-logs", buildQuery(params))
|
|
}
|
|
|
|
func (c *Client) GetMailLog(ctx context.Context, id uint) (*MailLogDetail, error) {
|
|
return get[*MailLogDetail](c, ctx, fmt.Sprintf("/api/v1/mail-logs/%d", id), nil)
|
|
}
|
|
|
|
func (c *Client) GetMailStats(ctx context.Context) ([]MailStatItem, error) {
|
|
return get[[]MailStatItem](c, ctx, "/api/v1/mail-logs/stats", nil)
|
|
}
|