init: 1.0.0

This commit is contained in:
Chang lue Tsen
2025-04-25 12:08:29 +09:00
commit 8addcc584b
1031 changed files with 76472 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package smtp
import (
"crypto/tls"
"gopkg.in/gomail.v2"
)
type Client struct {
conf Config
dailer *gomail.Dialer
}
type Config struct {
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Pass string `json:"pass"`
From string `json:"from"`
SSL bool `json:"ssl"`
SiteName string `json:"siteName"`
}
func NewClient(conf *Config) *Client {
if conf == nil {
return nil
}
dailer := gomail.NewDialer(conf.Host, conf.Port, conf.User, conf.Pass)
dailer.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS12,
ServerName: conf.Host,
}
return &Client{conf: *conf, dailer: dailer}
}
func (m *Client) Send(to []string, subject, body string) error {
msg := gomail.NewMessage()
msg.SetAddressHeader("From", m.conf.From, m.conf.SiteName)
msg.SetHeader("To", to...)
msg.SetHeader("Subject", subject)
msg.SetBody("text/html", body)
return m.dailer.DialAndSend(msg)
}
+24
View File
@@ -0,0 +1,24 @@
package smtp
import "testing"
func TestEmailSend(t *testing.T) {
t.Skipf("Skip TestEmailSend")
config := &Config{
Host: "smtp.mail.me.com",
Port: 587,
User: "support@ppanel.dev",
Pass: "password",
From: "support@ppanel.dev",
SSL: true,
SiteName: "",
}
address := []string{"tension@sparkdance.dev"}
subject := "test"
body := "test"
email := NewClient(config)
err := email.Send(address, subject, body)
if err != nil {
t.Errorf("send email error: %v", err)
}
}