chore: tweak comments

This commit is contained in:
Steven 2024-08-20 23:55:42 +08:00
parent a44e3e23d9
commit 85adb885fe
2 changed files with 4 additions and 26 deletions

View File

@ -27,7 +27,7 @@ func (la *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
case "Password:": case "Password:":
return []byte(la.password), nil return []byte(la.password), nil
default: default:
return nil, errors.New("Unknown fromServer") return nil, errors.New("unknown fromServer")
} }
} }
return nil, nil return nil, nil

View File

@ -1,27 +1,5 @@
// Package mail is a mail delivery plugin based on SMTP.
package mail package mail
// Usage:
// email := NewEmailMsg().SetFrom("yourselfhosted <from@yourselfhosted.com>").AddTo("Customer <to@yourselfhosted.com>").SetSubject("Test Email Subject").SetBody(`
// <!DOCTYPE html>
// <html>
// <head>
// <title>HTML Test</title>
// </head>
// <body>
// <h1>This is a mail delivery test.</h1>
// </body>
// </html>
// `)
// fmt.Printf("email: %+v\n", email)
// client := NewSMTPClient("smtp.gmail.com", 587)
// client.SetAuthType(SMTPAuthTypePlain)
// client.SetAuthCredentials("from@yourselfhosted.com", "nqxxxxxxxxxxxxxx")
// client.SetEncryptionType(SMTPEncryptionTypeSTARTTLS)
// if err := client.SendMail(email); err != nil {
// t.Fatalf("SendMail failed: %v", err)
// }
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
@ -80,7 +58,7 @@ func (e *Email) AddTo(to ...string) *Email {
for _, toAddress := range to { for _, toAddress := range to {
parsedAddr, err := mail.ParseAddress(toAddress) parsedAddr, err := mail.ParseAddress(toAddress)
if err != nil { if err != nil {
e.err = errors.Wrapf(err, "Invalid to address: %s", toAddress) e.err = errors.Wrapf(err, "invalid to address: %s", toAddress)
return e return e
} }
buf = append(buf, parsedAddr) buf = append(buf, parsedAddr)
@ -97,7 +75,7 @@ func (e *Email) SetSubject(subject string) *Email {
return e return e
} }
if e.subject != "" { if e.subject != "" {
e.err = errors.New("Subject already set") e.err = errors.New("subject already set")
return e return e
} }
e.subject = subject e.subject = subject
@ -192,7 +170,7 @@ func (c *SMTPClient) SendMail(e *Email) error {
case SMTPEncryptionTypeSTARTTLS: case SMTPEncryptionTypeSTARTTLS:
return e.e.SendWithStartTLS(fmt.Sprintf("%s:%d", c.host, c.port), c.getAuth(), &tls.Config{InsecureSkipVerify: true}) return e.e.SendWithStartTLS(fmt.Sprintf("%s:%d", c.host, c.port), c.getAuth(), &tls.Config{InsecureSkipVerify: true})
default: default:
return errors.Errorf("Unknown SMTP encryption type: %d", c.encryptionType) return errors.Errorf("unknown SMTP encryption type: %d", c.encryptionType)
} }
} }