Files
mailx/smtp/smtp_test.go
T

106 lines
2.3 KiB
Go
Raw Normal View History

2024-11-20 19:42:07 +08:00
package smtp_test
import (
"context"
"fmt"
"testing"
"code.yun.ink/pkg/mailx/interfaces"
"code.yun.ink/pkg/mailx/smtp"
)
func TestMail(t *testing.T) {
2025-08-10 21:17:10 +08:00
sm := smtp.NewSmtp()
2024-11-20 19:42:07 +08:00
ctx := context.Background()
2025-10-30 14:13:18 +08:00
// ini, err := sm.SetOption(ctx, interfaces.SetSmtp(&interfaces.EmailConfigDataSmtp{
// Username: "support@email.blueoceanpay.com",
// Password: "SupporT2017",
// ReplyTo: "",
// Host: "smtpdm-ap-southeast-1.aliyun.com",
// Port: "80",
// }))
// if err != nil {
// t.Fatal(err)
// }
2025-08-10 21:17:10 +08:00
ini, err := sm.SetOption(ctx, interfaces.SetSmtp(&interfaces.EmailConfigDataSmtp{
2025-10-30 14:13:18 +08:00
IsSSL: true,
Username: "demo@yunink.net",
Password: "aAhVPzHydLoc9Fj8",
2025-08-10 21:17:10 +08:00
ReplyTo: "",
2025-10-30 14:13:18 +08:00
Host: "smtp.exmail.qq.com",
Port: "465",
2025-08-10 21:17:10 +08:00
}))
2024-11-20 19:42:07 +08:00
if err != nil {
t.Fatal(err)
}
2025-10-30 14:13:18 +08:00
// req, err := http.Get("https://baidu.com")
// if err != nil {
// t.Fatal(err)
// }
// defer req.Body.Close()
// by, err := io.ReadAll(req.Body)
// if err != nil {
// t.Fatal(err)
// }
2024-11-20 19:42:07 +08:00
msg := interfaces.Message{
2025-10-30 14:13:18 +08:00
Form: "demo@yunink.net",
2024-11-20 19:42:07 +08:00
To: []string{"995116474@qq.com"},
Cc: []string{"287852692@qq.com"},
Bcc: []string{"1362716835@qq.com"},
ReplyTo: "huangxinyun@dreaminglife.cn",
2025-10-30 14:13:18 +08:00
Subject: "测试邮件",
Body: "这是测试邮件", //string(by),
2025-11-21 14:01:43 +08:00
Attachment: []interfaces.Attachment{
2024-11-20 19:42:07 +08:00
// {
// Name: "/code/statistic/out.xlsx",
// ContentType: "",
// WithFile: true,
// },
// {
// Name: "/code/statistic/origin.xlsx",
// ContentType: "",
// WithFile: true,
// },
// {
// Name: "/code/statistic/out2.xlsx",
// ContentType: "",
// WithFile: true,
// },
},
}
err = ini.Send(ctx, msg)
fmt.Println(err)
}
// func TestQQ(t *testing.T) {
// // 发件人邮箱
// from := "995116474@qq.com"
// // 授权码,而非密码
// authCode := "xxxxxxxxxxxxxxxxxxxxxx"
// // 收件人邮箱,可以是多个收件人
// to := []string{"yun@yun.ink"}
// // 邮件服务器信息
// smtpHost := "smtp.qq.com"
// smtpPort := "587" // 或使用465,根据你的SMTP服务器要求设置
// mail := mailx.NewMailx(from, authCode, smtpHost, smtpPort)
// msg := mailx.Message{
// To: to,
// Subject: "test mail",
// Body: "测试",
// }
// err := mail.Send(msg)
// fmt.Println(err)
// }