optimized_go_tools/am_docs/smtp.md
2024-07-08 11:14:19 +08:00

50 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.

# SMTP 发信服务包
用于通过Email的SMTP服务发送电子邮件。
## 使用方法
### 配置服务连接
```go
var emailConnection = am_smtp.EmailConnection{
Server: "smtp.example.com",
Port: 587,
Username: "example@example.com",
Password: "123456"
}
```
### 发送纯文字邮件
```go
am_smtp.SendPlainEmail(
"example@example.com", // from发信邮箱
[]string{"to@to.com"}, // to收信邮箱可以多个
"subject", // subject邮件主题
"content", // text邮件内容
emailConnection // conn上一步设定的email connection信息
)
```
### 发送HTML邮件
```go
// 设定html路径
pwd, err := os.Getwd()
path := filepath.Join(pwd, "template", "signup", "template.html")
// 设定填充数据(有的话)
type EmailData struct {
Code string
Time string
}
var emailData = EmailData{
...
}
// 发送
am_smtp.SendHTMLEmail(
"example@example.com", // from发信邮箱
[]string{"to@to.com"}, // to收信邮箱可以多个
"subject", // subject邮件主题
path, // htmlHTML模板的路径
emailData, // 填充数据
emailConnection, // conn上一步设定的email connection信息
)
```