Files
4566704 a6ba78c92c feat(mail): 自 go-hua 迁入 SMTP 邮件发送封装
- SendToMail 支持收/抄/密送与回复地址、HTML 或文本正文
- 附测试、examples/mail 例程与包 README(注明不支持 465 加密端口)
2026-09-20 12:29:38 +08:00

35 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# mail
SMTP 邮件发送封装:单函数 `SendToMail` 支持收件人/抄送/密送/回复地址,
`mailType` 选择 HTML 或纯文本正文。
> 迁移自 go-hua/mail,代码保持原样。
## 用法
```go
import "git.zeroonesoft.cn/golib/zogo/mail"
err := mail.SendToMail(
"user@example.com", // SMTP 用户名
"password-or-auth-code", // 密码/授权码
"smtp.example.com:25", // SMTP 服务器(host:port)
"user@example.com", // 发件人
"告警通知", // 主题
"<b>CPU 超限</b>", // 正文
"html", // "html" 或其他(纯文本)
"reply@example.com", // Reply-To
[]string{"a@example.com"}, // 收件人
[]string{"b@example.com"}, // 抄送
nil, // 密送
)
```
完整可运行例程:[examples/mail/main.go](../examples/mail/main.go)
## 注意
- 不支持 SSL/TLS 端口(465),走明文 SMTP 或 STARTTLS 由服务器协商;现在多数
公网邮箱要求授权码 + 加密端口,此包更适合内网 SMTP 中继。
- 邮件头未做 RFC 2047 编码,中文主题请确认服务器兼容(内网中继一般没问题)。