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
Add tables and structs related to sending mail
lotk22521491e35e
diff --git a/core/internal/model/entity/batch_mail.go b/core/internal/model/entity/batch_mail.gonew file mode 100644index 00000000..1c800dba--- /dev/null+++ b/core/internal/model/entity/batch_mail.go@@ -0,0 +1,66 @@+package entity++// ContactGroup Entity+type ContactGroup struct {+ Id int `json:"id" dc:"Group ID"`+ Name string `json:"name" dc:"Group Name"`+ Description string `json:"description" dc:"Description"`+ CreateTime int `json:"create_time" dc:"Create Time"`+ UpdateTime int `json:"update_time" dc:"Update Time"`+}++// Contact Entity+type Contact struct {+ Id int `json:"id" dc:"Contact ID"`+ Email string `json:"email" dc:"Email Address"`+ GroupId int `json:"group_id" dc:"Group ID"`+ Active int `json:"active" dc:"Status(1:Subscribed 0:Unsubscribed)"`+ TaskId int `json:"task_id" dc:"Bulk Mail Task ID"`+ CreateTime int `json:"create_time" dc:"Create Time"`+}++// EmailTemplate Entity+type EmailTemplate struct {+ Id int `json:"id" description:"Template ID" orm:"id"`+ TempName string `json:"temp_name" description:"Template Name" orm:"temp_name"`+ AddType int `json:"add_type" description:"Type" orm:"add_type"`+ Content string `json:"content" description:"Email Content" orm:"content"`+ Render string `json:"render" description:"Render Data" orm:"render"`+ CreateTime int `json:"create_time" description:"Create Time" orm:"create_time"`+ UpdateTime int `json:"update_time" description:"Update Time" orm:"update_time"`+}++// EmailTask Entity+type EmailTask struct {+ Id int `json:"id" dc:"Task ID"`+ TaskName string `json:"task_name" dc:"Task Name"`+ Addresser string `json:"addresser" dc:"Sender"`+ Subject string `json:"subject" dc:"Subject"`+ FullName string `json:"full_name" dc:"Sender Name"`+ RecipientCount int `json:"recipient_count" dc:"Recipient Count"`+ TaskProcess int `json:"task_process" dc:"Task Status"`+ Pause int `json:"pause" dc:"Pause Status"`+ TemplateId int `json:"template_id" dc:"Template ID"`+ IsRecord int `json:"is_record" dc:"Record to Outbox"`+ Unsubscribe int `json:"unsubscribe" dc:"Allow Unsubscribe"`+ Threads int `json:"threads" dc:"Thread Count"`+ Etypes string `json:"etypes" dc:"Contact Group IDs"`+ TrackOpen int `json:"track_open" dc:"Track Opens"`+ TrackClick int `json:"track_click" dc:"Track Clicks"`+ StartTime int `json:"start_time" dc:"Start Time"`+ CreateTime int `json:"create_time" dc:"Create Time"`+ UpdateTime int `json:"update_time" dc:"Update Time"`+ Remark string `json:"remark" dc:"Remark"`+ Active int `json:"active" dc:"Status"`+}++// RecipientInfo Entity+type RecipientInfo struct {+ Id int `json:"id" dc:"Recipient ID"`+ TaskId int `json:"task_id" dc:"Task ID"`+ Recipient string `json:"recipient" dc:"Recipient Email"`+ IsSent int `json:"is_sent" dc:"Send Status"`+ SentTime int `json:"sent_time" dc:"Send Time"`+ MessageId string `json:"message_id" dc:"Email Message-ID"`+ CreateTime int `json:"create_time" dc:"Create Time"`+}diff --git a/core/internal/service/database_initialization/batch_mail.go b/core/internal/service/database_initialization/batch_mail.gonew file mode 100644index 00000000..2ec16f15--- /dev/null+++ b/core/internal/service/database_initialization/batch_mail.go@@ -0,0 +1,90 @@+package database_initialization++import (+ "context"+ "github.com/gogf/gf/v2/frame/g"+)++func init() {+ registerHandler(func() {+ batchMailSQLList := []string{++ `CREATE TABLE IF NOT EXISTS contact_groups (+ id SERIAL PRIMARY KEY,+ name VARCHAR(255) NOT NULL,+ description TEXT,+ create_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ update_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ UNIQUE(name)+ )`,++ `CREATE TABLE IF NOT EXISTS contacts (+ id SERIAL PRIMARY KEY,+ email VARCHAR(320) NOT NULL,+ group_id INTEGER,+ active INTEGER DEFAULT 1,+ task_id INTEGER DEFAULT 0,+ create_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ FOREIGN KEY (group_id) REFERENCES contact_groups(id) ON DELETE SET NULL,+ UNIQUE(group_id, email)+ )`,++ `CREATE TABLE IF NOT EXISTS email_templates (+ id SERIAL PRIMARY KEY,+ temp_name VARCHAR(255),+ add_type SMALLINT NOT NULL DEFAULT 0,+ content TEXT NOT NULL DEFAULT '',+ render TEXT NOT NULL DEFAULT '',+ create_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ update_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ UNIQUE(temp_name)+ )`,++ `CREATE TABLE IF NOT EXISTS email_tasks (+ id SERIAL PRIMARY KEY,+ task_name VARCHAR(255) NOT NULL,+ addresser VARCHAR(320) NOT NULL,+ subject TEXT,+ full_name VARCHAR(255),+ remark TEXT,+ recipient_count INTEGER NOT NULL,+ task_process SMALLINT NOT NULL DEFAULT 0,+ pause SMALLINT NOT NULL DEFAULT 0,+ template_id INTEGER NOT NULL,+ is_record SMALLINT NOT NULL DEFAULT 0,+ unsubscribe SMALLINT NOT NULL DEFAULT 0,+ threads INTEGER NOT NULL DEFAULT 0,+ etypes VARCHAR(320) NOT NULL DEFAULT '1',+ track_open SMALLINT NOT NULL DEFAULT 1,+ track_click SMALLINT NOT NULL DEFAULT 1,+ start_time INTEGER NOT NULL DEFAULT 0,+ create_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ update_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ active SMALLINT NOT NULL DEFAULT 0,+ FOREIGN KEY (template_id) REFERENCES email_templates(id)+ )`,++ `CREATE TABLE IF NOT EXISTS recipient_info (+ id SERIAL PRIMARY KEY,+ task_id INTEGER NOT NULL,+ recipient VARCHAR(320) NOT NULL,+ is_sent SMALLINT DEFAULT 0,+ sent_time INTEGER NOT NULL DEFAULT 0,+ message_id TEXT NOT NULL,+ create_time INTEGER NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),+ FOREIGN KEY (task_id) REFERENCES email_tasks(id) ON DELETE CASCADE,+ UNIQUE(task_id, recipient)+ )`,+ }++ for _, sql := range batchMailSQLList {+ _, err := g.DB().Exec(context.Background(), sql)+ if err != nil {+ g.Log().Error(context.Background(), "Failed to execute batch mail SQL:", err, sql)+ return+ }+ }++ g.Log().Info(context.Background(), "Batch mail tables initialized successfully")+ })+}