BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Added sender api to batch send
lotk7f862b9d48c4
diff --git a/core/api/batch_mail/v1/api_mail.go b/core/api/batch_mail/v1/api_mail.goindex 3b410bae..ed5b2848 100644--- a/core/api/batch_mail/v1/api_mail.go+++ b/core/api/batch_mail/v1/api_mail.go@@ -150,3 +150,15 @@ type ApiMailSendReq struct {type ApiMailSendRes struct {api_v1.StandardRes}++type ApiMailBatchSendReq struct {+ g.Meta `path:"/batch_mail/api/batch_send" method:"post" tags:"ApiMail" summary:"call api batch send mail"`+ ApiKey string `json:"x-api-key" dc:"API Key" in:"header"`+ Addresser string `json:"addresser" dc:"addresser"`+ Recipients []string `json:"recipients" dc:"recipients"`+ Attribs map[string]string `json:"attribs" dc:"Custom properties"`+}++type ApiMailBatchSendRes struct {+ api_v1.StandardRes+}diff --git a/core/internal/controller/batch_mail/batch_mail_v1_api_mail_batch_send.go b/core/internal/controller/batch_mail/batch_mail_v1_api_mail_batch_send.goindex 77d9f31e..b51e179f 100644--- a/core/internal/controller/batch_mail/batch_mail_v1_api_mail_batch_send.go+++ b/core/internal/controller/batch_mail/batch_mail_v1_api_mail_batch_send.go@@ -16,7 +16,7 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcres = &v1.ApiMailBatchSendRes{}clientIP := g.RequestFromCtx(ctx).GetClientIp()- // 1. 校验API Key+ // 1. check API KeyapiTemplate, err := getApiTemplateByKey(ctx, req.ApiKey, clientIP)if err != nil {res.Code = 1001@@ -24,7 +24,7 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcreturn res, nil}- // 2. 校验IP+ // 2. check client IPerr = CheckClientIP(ctx, apiTemplate.Id, clientIP)if err != nil {res.Code = 1002@@ -32,7 +32,7 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcreturn res, nil}- // 3. 校验邮件模板+ // 3. check email template_, err = getEmailTemplateById(ctx, apiTemplate.TemplateId)if err != nil {res.Code = 1004@@ -40,7 +40,7 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcreturn res, nil}- // 4. 校验收件人+ // 4. check recipientif len(req.Recipients) == 0 {res.Code = 1003res.SetError(gerror.New(public.LangCtx(ctx, "Recipients cannot be empty")))@@ -49,6 +49,8 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcvalidRecipients := make([]string, 0, len(req.Recipients))for _, recipient := range req.Recipients {+ // remove extra spaces+ recipient = strings.TrimSpace(recipient)if recipient != "" && strings.Contains(recipient, "@") {validRecipients = append(validRecipients, recipient)}@@ -59,20 +61,19 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcreturn res, nil}- // 5. 处理发件人+ // 5. process addresseraddresser := req.Addresserif addresser == "" {addresser = apiTemplate.Addresser}- // 6. 批量处理联系人和日志数据batchData := make([]g.Map, 0, len(validRecipients))now := int(time.Now().Unix())for _, recipient := range validRecipients {- // 处理联系人和分组+_, err = ensureContactAndGroup(ctx, recipient, apiTemplate.Id)if err != nil {- // 某个收件人失败,跳过+continue}// 生成messageId@@ -88,7 +89,7 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatc"recipient": recipient,"message_id": messageId,"addresser": addresser,- "status": 0, // 待发送+ "status": 0,"error_message": "","send_time": 0,"create_time": now,@@ -102,7 +103,6 @@ func (c *ControllerV1) ApiMailBatchSend(ctx context.Context, req *v1.ApiMailBatcreturn res, nil}- // 7. 批量插入日志表,分批处理batchSize := 1000for i := 0; i < len(batchData); i += batchSize {end := i + batchSize