All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 6m15s
120 lines
3.4 KiB
Go
120 lines
3.4 KiB
Go
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)
|
|
}
|
|
}
|