完善多个通道
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package smtp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.yun.ink/pkg/mailx/interfaces"
|
||||
"code.yun.ink/pkg/mailx/smtp"
|
||||
"github.com/yuninks/loggerx"
|
||||
)
|
||||
|
||||
func TestMail(t *testing.T) {
|
||||
sm := smtp.Smtp{}
|
||||
ctx := context.Background()
|
||||
|
||||
logger := loggerx.NewLogger(ctx)
|
||||
|
||||
ini, err := sm.InitEmail(ctx, interfaces.EmailConfigData{
|
||||
Smtp: &interfaces.EmailConfigDataSmtp{
|
||||
Username: "test@email.aisz.org",
|
||||
Password: "FDuSoJKiC9tNSDIG6DFh",
|
||||
ReplyTo: "",
|
||||
Host: "smtpdm.aliyun.com",
|
||||
Port: "80",
|
||||
},
|
||||
}, logger)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
msg := interfaces.Message{
|
||||
To: []string{"995116474@qq.com"},
|
||||
Cc: []string{"287852692@qq.com"},
|
||||
Bcc: []string{"1362716835@qq.com"},
|
||||
ReplyTo: "huangxinyun@dreaminglife.cn",
|
||||
Subject: "test mail",
|
||||
Body: string(by),
|
||||
Attachment: []interfaces.MessageAttachment{
|
||||
// {
|
||||
// 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)
|
||||
// }
|
||||
Reference in New Issue
Block a user