Skip to content

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

api sender removes unsubscribe data

lotk24b23dc7a296
diff --git a/core/api/batch_mail/v1/api_mail.go b/core/api/batch_mail/v1/api_mail.go
index 55a0237d..ab61caee 100644
--- a/core/api/batch_mail/v1/api_mail.go
+++ b/core/api/batch_mail/v1/api_mail.go
@@ -71,16 +71,16 @@ type ApiTemplatesListReq struct {
type ApiTemplatesInfo struct {
ApiTemplates
- SendCount int `json:"send_count" dc:"send count"`
- SuccessCount int `json:"success_count" dc:"success count"`
- FailCount int `json:"fail_count" dc:"fail count"`
- OpenRate float64 `json:"open_rate" dc:"open rate"`
- ClickRate float64 `json:"click_rate" dc:"click rate"`
- DeliveryRate float64 `json:"delivery_rate" dc:"delivery rate"`
- BounceRate float64 `json:"bounce_rate" dc:"bounce rate"`
- UnsubscribeCount int `json:"unsubscribe_count" dc:"unsubscribe count"`
- IpWhitelist []string `json:"ip_whitelist" dc:"IP whitelist"`
- ServerAddresser string `json:"server_addresser" dc:"server addresser"`
+ SendCount int `json:"send_count" dc:"send count"`
+ SuccessCount int `json:"success_count" dc:"success count"`
+ FailCount int `json:"fail_count" dc:"fail count"`
+ OpenRate float64 `json:"open_rate" dc:"open rate"`
+ ClickRate float64 `json:"click_rate" dc:"click rate"`
+ DeliveryRate float64 `json:"delivery_rate" dc:"delivery rate"`
+ BounceRate float64 `json:"bounce_rate" dc:"bounce rate"`
+ //UnsubscribeCount int `json:"unsubscribe_count" dc:"unsubscribe count"`
+ IpWhitelist []string `json:"ip_whitelist" dc:"IP whitelist"`
+ ServerAddresser string `json:"server_addresser" dc:"server addresser"`
}
type ApiTemplatesListRes struct {
@@ -92,13 +92,13 @@ type ApiTemplatesListRes struct {
}
type ApiSummaryStats struct {
- TotalSend int `json:"total_send" dc:"total send count"`
- AvgDeliveryRate float64 `json:"avg_delivery_rate" dc:"average delivery rate"`
- AvgOpenRate float64 `json:"avg_open_rate" dc:"average open rate"`
- AvgClickRate float64 `json:"avg_click_rate" dc:"average click rate"`
- AvgBounceRate float64 `json:"avg_bounce_rate" dc:"average bounce rate"`
- AvgUnsubRate float64 `json:"avg_unsub_rate" dc:"average unsubscribe rate"`
- TotalUnsubscribe int `json:"total_unsubscribe" dc:"total unsubscribe count"`
+ TotalSend int `json:"total_send" dc:"total send count"`
+ AvgDeliveryRate float64 `json:"avg_delivery_rate" dc:"average delivery rate"`
+ AvgOpenRate float64 `json:"avg_open_rate" dc:"average open rate"`
+ AvgClickRate float64 `json:"avg_click_rate" dc:"average click rate"`
+ AvgBounceRate float64 `json:"avg_bounce_rate" dc:"average bounce rate"`
+ //AvgUnsubRate float64 `json:"avg_unsub_rate" dc:"average unsubscribe rate"`
+ //TotalUnsubscribe int `json:"total_unsubscribe" dc:"total unsubscribe count"`
}
type ApiOverviewStatsReq struct {
diff --git a/core/internal/controller/batch_mail/batch_mail_v1_api_overview_stats.go b/core/internal/controller/batch_mail/batch_mail_v1_api_overview_stats.go
index b4dad9a2..a16565d5 100644
--- a/core/internal/controller/batch_mail/batch_mail_v1_api_overview_stats.go
+++ b/core/internal/controller/batch_mail/batch_mail_v1_api_overview_stats.go
@@ -21,7 +21,7 @@ func (c *ControllerV1) ApiOverviewStats(ctx context.Context, req *v1.ApiOverview
return nil, err
}
- var totalSend, totalDelivered, totalBounced, totalOpened, totalClicked, totalUnsub int
+ var totalSend, totalDelivered, totalBounced, totalOpened, totalClicked int
for _, api := range apiList {
@@ -68,36 +68,36 @@ func (c *ControllerV1) ApiOverviewStats(ctx context.Context, req *v1.ApiOverview
totalOpened += openedCount.Int()
totalClicked += clickedCount.Int()
- // count unsubscribe
- recipients := []string{}
- _, _ = g.DB().Model("api_mail_logs").Where("api_id", api.Id).Fields("recipient").Array(&recipients)
- unsubscribeCount := 0
- if len(recipients) > 0 {
- unsubscribeCount, _ = g.DB().Model("bm_contacts").
- Where("email", recipients).
- Where("active", 0).
- WhereGTE("create_time", api.CreateTime).
- Count()
- }
- totalUnsub += unsubscribeCount
+ //// count unsubscribe
+ //recipients := []string{}
+ //_, _ = g.DB().Model("api_mail_logs").Where("api_id", api.Id).Fields("recipient,api_id").Array(&recipients)
+ //unsubscribeCount := 0
+ //if len(recipients) > 0 {
+ // unsubscribeCount, _ = g.DB().Model("bm_contacts").
+ // Where("email", recipients).
+ // Where("active", 0).
+ // WhereGTE("create_time", api.CreateTime).
+ // Count()
+ //}
+ //totalUnsub += unsubscribeCount
}
- var avgDeliveryRate, avgOpenRate, avgClickRate, avgBounceRate, avgUnsubRate float64
+ var avgDeliveryRate, avgOpenRate, avgClickRate, avgBounceRate float64
if totalSend > 0 {
avgDeliveryRate = public.Round(float64(totalDelivered)/float64(totalSend)*100, 2)
avgOpenRate = public.Round(float64(totalOpened)/float64(totalSend)*100, 2)
avgClickRate = public.Round(float64(totalClicked)/float64(totalSend)*100, 2)
avgBounceRate = public.Round(float64(totalBounced)/float64(totalSend)*100, 2)
- avgUnsubRate = public.Round(float64(totalUnsub)/float64(totalSend)*100, 2)
+ //avgUnsubRate = public.Round(float64(totalUnsub)/float64(totalSend)*100, 2)
}
res.Data = v1.ApiSummaryStats{
- TotalSend: totalSend,
- AvgDeliveryRate: avgDeliveryRate,
- AvgOpenRate: avgOpenRate,
- AvgClickRate: avgClickRate,
- AvgBounceRate: avgBounceRate,
- AvgUnsubRate: avgUnsubRate,
- TotalUnsubscribe: totalUnsub,
+ TotalSend: totalSend,
+ AvgDeliveryRate: avgDeliveryRate,
+ AvgOpenRate: avgOpenRate,
+ AvgClickRate: avgClickRate,
+ AvgBounceRate: avgBounceRate,
+ //AvgUnsubRate: avgUnsubRate,
+ //TotalUnsubscribe: totalUnsub,
}
res.SetSuccess(public.LangCtx(ctx, "Statistics successful"))
return res, nil
diff --git a/core/internal/controller/batch_mail/batch_mail_v1_api_templates_list.go b/core/internal/controller/batch_mail/batch_mail_v1_api_templates_list.go
index fded0123..29c1f77d 100644
--- a/core/internal/controller/batch_mail/batch_mail_v1_api_templates_list.go
+++ b/core/internal/controller/batch_mail/batch_mail_v1_api_templates_list.go
@@ -103,17 +103,18 @@ func (c *ControllerV1) ApiTemplatesList(ctx context.Context, req *v1.ApiTemplate
}
// count unsubscribe
- recipients := []string{}
- _, err = g.DB().Model("api_mail_logs").Where("api_id", item.Id).Fields("recipient").Array(&recipients)
- unsubscribeCount := 0
- if len(recipients) > 0 {
- unsubscribeCount, _ = g.DB().Model("bm_contacts").
- Where("email", recipients).
- Where("active", 0).
- WhereGTE("create_time", item.CreateTime).
- Count()
- }
- item.UnsubscribeCount = unsubscribeCount
+ //recipients := []string{}
+ //_, err = g.DB().Model("api_mail_logs").Where("api_id", item.Id).Fields("recipient").Array(&recipients)
+ //unsubscribeCount := 0
+ //if len(recipients) > 0 {
+ // unsubscribeCount, _ = g.DB().Model("bm_contacts").
+ // Where("email", recipients).
+ // Where("active", 0).
+ // WhereGTE("create_time", item.CreateTime).
+ // Count()
+ //}
+ //item.UnsubscribeCount = unsubscribeCount
+
// get IP whitelist
var ipRows []struct{ Ip string }
err = g.DB().Model("api_ip_whitelist").