This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/initialize"
|
||||
"github.com/perfect-panel/server/internal/config"
|
||||
loggerLog "github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/conf"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var c config.Config
|
||||
conf.MustLoad("etc/ppanel.yaml", &c)
|
||||
|
||||
fmt.Println("Initializing ServiceContext...")
|
||||
svcCtx := svc.NewServiceContext(c)
|
||||
initialize.Email(svcCtx)
|
||||
fmt.Println("ServiceContext initialized.")
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// 模拟真实数据
|
||||
content := map[string]interface{}{
|
||||
"Type": 1,
|
||||
"SiteLogo": c.Site.SiteLogo,
|
||||
"SiteName": c.Site.SiteName,
|
||||
"Expire": 15,
|
||||
"Code": "123456",
|
||||
}
|
||||
|
||||
messageLog := loggerLog.Message{
|
||||
Platform: svcCtx.Config.Email.Platform,
|
||||
To: "shanshanzhong147@gmail.com",
|
||||
Subject: "PPanel Test - Verify Email (Register)",
|
||||
Content: content,
|
||||
Status: 1,
|
||||
}
|
||||
|
||||
emailLog, err := messageLog.Marshal()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
systemLog := &loggerLog.SystemLog{
|
||||
Type: loggerLog.TypeEmailMessage.Uint8(),
|
||||
Date: time.Now().Format("2006-01-02"),
|
||||
ObjectID: 0,
|
||||
Content: string(emailLog),
|
||||
}
|
||||
|
||||
fmt.Println("Attempting to insert into system_logs...")
|
||||
err = svcCtx.LogModel.Insert(ctx, systemLog)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Insert failed!\n")
|
||||
fmt.Printf("Error Type: %T\n", err)
|
||||
fmt.Printf("Error String: %s\n", err.Error())
|
||||
fmt.Printf("Detailed Error: %+v\n", err)
|
||||
} else {
|
||||
fmt.Println("✅ Insert successful!")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/perfect-panel/server/initialize"
|
||||
"github.com/perfect-panel/server/internal/config"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/conf"
|
||||
emailLogic "github.com/perfect-panel/server/queue/logic/email"
|
||||
"github.com/perfect-panel/server/queue/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var c config.Config
|
||||
conf.MustLoad("etc/ppanel.yaml", &c)
|
||||
|
||||
if !c.Email.Enable {
|
||||
log.Fatal("Email is disabled in config. Please enable it in etc/ppanel.yaml")
|
||||
}
|
||||
|
||||
// Initialize ServiceContext
|
||||
svcCtx := svc.NewServiceContext(c)
|
||||
initialize.Email(svcCtx)
|
||||
ctx := context.Background()
|
||||
|
||||
// Target email
|
||||
targetEmail := "shanshanzhong147@gmail.com"
|
||||
fmt.Printf("Preparing to send emails to: %s\n", targetEmail)
|
||||
|
||||
senderLogic := emailLogic.NewSendEmailLogic(svcCtx)
|
||||
|
||||
// 1. Verify Email (Register)
|
||||
fmt.Println("\n[1/5] Sending Registration/Verify Email...")
|
||||
send(ctx, senderLogic, types.SendEmailPayload{
|
||||
Type: types.EmailTypeVerify,
|
||||
Email: targetEmail,
|
||||
Subject: "PPanel Test - Verify Email (Register)",
|
||||
Content: map[string]interface{}{
|
||||
"Type": 1, // 1: Register
|
||||
"SiteLogo": c.Site.SiteLogo,
|
||||
"SiteName": c.Site.SiteName,
|
||||
"Expire": 15,
|
||||
"Code": "123456",
|
||||
},
|
||||
})
|
||||
|
||||
// 2. Verify Email (Password Reset)
|
||||
fmt.Println("\n[2/5] Sending Password Reset/Verify Email...")
|
||||
send(ctx, senderLogic, types.SendEmailPayload{
|
||||
Type: types.EmailTypeVerify,
|
||||
Email: targetEmail,
|
||||
Subject: "PPanel Test - Verify Email (Password Reset)",
|
||||
Content: map[string]interface{}{
|
||||
"Type": 2, // 2: Password Reset
|
||||
"SiteLogo": c.Site.SiteLogo,
|
||||
"SiteName": c.Site.SiteName,
|
||||
"Expire": 15,
|
||||
"Code": "654321",
|
||||
},
|
||||
})
|
||||
|
||||
// 3. Maintenance Email
|
||||
fmt.Println("\n[3/5] Sending Maintenance Email...")
|
||||
send(ctx, senderLogic, types.SendEmailPayload{
|
||||
Type: types.EmailTypeMaintenance,
|
||||
Email: targetEmail,
|
||||
Subject: "PPanel Test - Maintenance Notice",
|
||||
Content: map[string]interface{}{
|
||||
"SiteLogo": c.Site.SiteLogo,
|
||||
"SiteName": c.Site.SiteName,
|
||||
"MaintenanceDate": "2026-01-01",
|
||||
"MaintenanceTime": "12:00 - 14:00 (UTC+8)",
|
||||
},
|
||||
})
|
||||
|
||||
// 4. Expiration Email
|
||||
fmt.Println("\n[4/5] Sending Expiration Email...")
|
||||
send(ctx, senderLogic, types.SendEmailPayload{
|
||||
Type: types.EmailTypeExpiration,
|
||||
Email: targetEmail,
|
||||
Subject: "PPanel Test - Subscription Expiration",
|
||||
Content: map[string]interface{}{
|
||||
"SiteLogo": c.Site.SiteLogo,
|
||||
"SiteName": c.Site.SiteName,
|
||||
"ExpireDate": "2026-02-01",
|
||||
},
|
||||
})
|
||||
|
||||
// 5. Traffic Exceed Email
|
||||
fmt.Println("\n[5/5] Sending Traffic Exceed Email...")
|
||||
send(ctx, senderLogic, types.SendEmailPayload{
|
||||
Type: types.EmailTypeTrafficExceed,
|
||||
Email: targetEmail,
|
||||
Subject: "PPanel Test - Traffic Exceeded",
|
||||
Content: map[string]interface{}{
|
||||
"SiteLogo": c.Site.SiteLogo,
|
||||
"SiteName": c.Site.SiteName,
|
||||
"UsedTraffic": "100GB",
|
||||
"MaxTraffic": "100GB",
|
||||
},
|
||||
})
|
||||
|
||||
fmt.Println("\nAll tests completed. Please check your inbox.")
|
||||
}
|
||||
|
||||
func send(ctx context.Context, l *emailLogic.SendEmailLogic, payload types.SendEmailPayload) {
|
||||
data, _ := json.Marshal(payload)
|
||||
task := asynq.NewTask(types.ForthwithSendEmail, data)
|
||||
if err := l.ProcessTask(ctx, task); err != nil {
|
||||
fmt.Printf("❌ Failed to send %s: %v\n", payload.Type, err)
|
||||
} else {
|
||||
fmt.Printf("✅ Sent %s successfully.\n", payload.Type)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user