Documentation
¶
Overview ¶
Package email 提供基于 SMTP 协议的邮件发送工具。
支持两种发送方式:
- SendHtmlByTLS: 使用 STARTTLS 方式发送(适用于 587 端口)
- SendHtml: 使用直接 TLS 连接发送(适用于 465 端口)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CRAMMD5Auth ¶
CRAMMD5Auth 创建 CRAM-MD5 认证实例(RFC 2195)。 使用给定的用户名和密钥,通过挑战-响应机制向服务器进行身份认证。
func SendHtml ¶
func SendHtml(conf SmtpConfig, receiver string, subject string, text string) error
SendHtml 通过直接 TLS 连接发送 HTML 邮件。 适用于要求直接建立 TLS 连接的 SMTP 服务器(通常使用 465 端口)。
参数:
- conf: SMTP 服务器配置
- receiver: 收件人邮箱地址
- subject: 邮件主题
- text: HTML 格式的邮件正文
返回:
- error: 发送失败时返回错误
该方法手动建立 TLS 连接并完成 SMTP 会话,按以下顺序执行: 1. 建立 TLS 连接 2. 创建 SMTP 客户端并认证 3. 设置发件人、收件人 4. 构造邮件内容并写入 5. 发送 QUIT 关闭会话
func SendHtmlByTLS ¶
func SendHtmlByTLS(conf SmtpConfig, receiver string, subject string, text string) error
SendHtmlByTLS 通过 STARTTLS 方式发送 HTML 邮件。 适用于支持 STARTTLS 升级的 SMTP 服务器(通常使用 587 端口)。
参数:
- conf: SMTP 服务器配置
- receiver: 收件人邮箱地址
- subject: 邮件主题
- text: HTML 格式的邮件正文
返回:
- error: 发送失败时返回错误
Types ¶
type SmtpConfig ¶
type SmtpConfig struct {
Sender string // 发件人地址(如 "noreply@example.com")
Username string // SMTP 认证用户名
Password string // SMTP 认证密码
Host string // SMTP 服务器地址(如 "smtp.example.com")
Port int // SMTP 服务器端口(TLS 通常为 465,STARTTLS 通常为 587)
InsecureSkipVerify bool // 是否跳过 TLS 证书验证,默认 false(启用验证);仅在自签名证书等场景下设为 true
}
SmtpConfig SMTP 邮件服务器配置
Click to show internal directories.
Click to hide internal directories.