2023-12-27 18:16:21 +08:00
|
|
|
package mailx_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
2024-04-12 15:30:23 +08:00
|
|
|
|
|
|
|
|
"code.yun.ink/pkg/mailx"
|
2023-12-27 18:16:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMail(t *testing.T) {
|
|
|
|
|
mail := mailx.NewMailx("support@email.blueoceanpay.com", "SupporT2017", "smtpdm-ap-southeast-1.aliyun.com", "80")
|
|
|
|
|
|
|
|
|
|
msg := mailx.Message{
|
|
|
|
|
// Form: "support@email.blueoceanpay.com",
|
2024-04-12 15:30:23 +08:00
|
|
|
To: []string{"yun@blueoceanpay.com", "995116474@qq.com"},
|
|
|
|
|
Cc: []string{"287852692@qq.com"},
|
|
|
|
|
Bcc: []string{"1362716835@qq.com"},
|
|
|
|
|
Subject: "test mail",
|
|
|
|
|
Body: "测试文件",
|
2023-12-27 18:16:21 +08:00
|
|
|
Attachment: []mailx.Attachment{
|
|
|
|
|
// {
|
|
|
|
|
// 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 := mail.Send(msg)
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
2024-04-12 16:24:16 +08:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|