2024-11-20 19:42:07 +08:00
|
|
|
package mailgun_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-08-15 01:38:05 +08:00
|
|
|
"code.yun.ink/pkg/mailx"
|
2024-11-20 19:42:07 +08:00
|
|
|
"code.yun.ink/pkg/mailx/mailgun"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
apikey = "b87ece56257aa282dd3c809f683c60e5-32a0fef1-6327df27"
|
|
|
|
|
domain = "sandboxd045b2448880433785c34f72a7fd0d45.mailgun.org"
|
|
|
|
|
sender = "zhaoyang@dreaminglife.cn"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSendEmail(t *testing.T) {
|
2026-08-15 01:38:05 +08:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("skip real send in short mode")
|
|
|
|
|
}
|
|
|
|
|
client := mailgun.New(mailgun.Config{
|
|
|
|
|
APIKey: apikey,
|
2025-08-10 21:17:10 +08:00
|
|
|
Domain: domain,
|
|
|
|
|
Sender: sender,
|
2024-11-20 19:42:07 +08:00
|
|
|
})
|
2026-08-15 01:38:05 +08:00
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
err := client.Send(ctx, mailx.NewMessage().
|
|
|
|
|
To("995116474@qq.com").
|
|
|
|
|
Subject("test mail").
|
|
|
|
|
Body("Hello").
|
|
|
|
|
Build())
|
2024-11-20 19:42:07 +08:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
t.Log("send success")
|
|
|
|
|
}
|