- SendToMail 支持收/抄/密送与回复地址、HTML 或文本正文 - 附测试、examples/mail 例程与包 README(注明不支持 465 加密端口)
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// mail 包示例:SMTP 发送邮件(SendToMail)与收件人列表合并(MergeSlice)
|
||
package main
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"git.zeroonesoft.cn/golib/zogo/mail"
|
||
)
|
||
|
||
func main() {
|
||
// MergeSlice:合并收件人列表(to + cc + bcc 一次性提交给 SMTP)
|
||
merged := mail.MergeSlice([]string{"a@test.com", "b@test.com"}, []string{"c@test.com"})
|
||
fmt.Println("合并收件人:", merged)
|
||
|
||
// SendToMail 参数说明:
|
||
// user SMTP 账号
|
||
// password SMTP 密码/授权码
|
||
// host SMTP 服务器,如 "smtp.example.com:25"
|
||
// from 发件人地址
|
||
// subject 邮件主题
|
||
// body 邮件正文
|
||
// mailType "html" 为 HTML 邮件,其他值为纯文本
|
||
// replyToAddress 回复地址
|
||
// to / cc / bcc 收件人 / 抄送 / 密送列表
|
||
//
|
||
// 填入真实 SMTP 账号后调用即可发送:
|
||
//
|
||
// err := mail.SendToMail(
|
||
// "user@example.com", "password", "smtp.example.com:25",
|
||
// "user@example.com", "测试邮件", "<h1>hello</h1>", "html",
|
||
// "reply@example.com",
|
||
// []string{"to@example.com"}, []string{"cc@example.com"}, []string{},
|
||
// )
|
||
// if err != nil {
|
||
// fmt.Println("发送失败:", err)
|
||
// }
|
||
}
|