Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zizdlp committed Aug 21, 2024
1 parent 6c8921b commit 0ea8d16
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ compress:
server:
cd zbook_backend && \
REQUIRE_EMAIL_VERIFY=false go run cmd/server/main.go
mail:
cd zbook_backend && \
go run cmd/mail/main.go
gp:
cd zbook_backend && \
mkdir -p pb && \
Expand Down Expand Up @@ -67,9 +70,6 @@ migrateup:
migratedown:
cd zbook_backend && \
migrate -path db/migration -database "$(DB_SOURCE)" -verbose down
convert_db:
cd zbook_database && \
python convert.py
mmdb2psql:
cd zbook_backend && \
go run cmd/mmdb2psql/main.go ${CURRENT_DIR}/GeoLite2-City.mmdb
Expand Down
48 changes: 48 additions & 0 deletions zbook_backend/cmd/mail/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"log"

"github.com/zizdlp/zbook/mail"
"github.com/zizdlp/zbook/util"
)

func main() {
// 加载配置
config, err := util.LoadConfig(".")
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}

sender := mail.NewGmailSender(config.EmailSenderName, config.EmailSenderAddress, config.EmailSenderPassword)

subject := "A test email from @zizdlp.com"
// 模拟用户数据
user := struct {
Username string
}{
Username: "admin",
}
verifyUrl := "http://localhost:3000/verify_email?verification_id=66ca2c9313264f449648a6e2aa6f8cf0"

Title := "Verify Your Email Address"
emailSubject := "Thank you for registering with us! Please verify your email address by clicking the button below:"
buttonText := "Verify Email"
additionalText := "If you did not register for an account, please ignore this email or contact support if you have any questions."
base64Image, err := util.ReadImageBytesToBase64("./icons/logo.png")
if err != nil {
log.Fatalf("Failed to read image file: %v", err)
}

emailBody := fmt.Sprintf(util.EmailTemplate, Title, user.Username, emailSubject, verifyUrl, buttonText, additionalText, base64Image)

to := []string{"zizdlp@gmail.com"}

err = sender.SendEmail(subject, emailBody, to, nil, nil, nil, config.SmtpAuthAddress, config.SmtpServerAddress)
if err != nil {
log.Fatalf("Failed to send email: %v", err)
}

fmt.Println("Email sent successfully!")
}

0 comments on commit 0ea8d16

Please sign in to comment.