Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MessageEmail ¶
type MessageEmail struct {
// 发件人邮箱地址
From string
// 收件人邮箱地址列表
To []string
// 抄送人邮箱地址列表
Cc []string
// 邮件主题
Subject string
// 邮件正文
Body string
// 是否是HTML格式的正文
IsHTML bool
}
MessageEmail 用于表示邮件消息
type SenderEmail ¶
type SenderEmail struct {
// SMTP服务器地址
SMTPServer string
// SMTP服务器端口号
SMTPPort int
// 发件人邮箱账号
EmailAccount string
// 发件人邮箱密码
EmailPassword string
}
SenderEmail 用于发送邮件
func (*SenderEmail) SendEmail ¶
func (s *SenderEmail) SendEmail(message MessageEmail) error
SendEmail
该示例会发送一封邮件到recipient1@example.com和recipient2@example.com,抄送给cc@example.com, 主题为"测试邮件",内容为"Hello, World!"。 您可以按照上述示例修改EmailMessage结构体中的字段以发送不同的邮件。 // 初始化EmailSender
emailSender := SenderEmail{
SMTPServer: "smtp.qq.com",
SMTPPort: 587,
EmailAccount: "example@qq.com",
EmailPassword: "password",
}
// 准备邮件消息
message := MessageEmail{
From: "example@qq.com",
To: []string{"recipient1@example.com", "recipient2@example.com"},
Cc: []string{"cc@example.com"},
Subject: "测试邮件",
Body: "<h1>Hello, World!</h1><p>This is a test email.</p>",
IsHTML: true,
}
// 发送邮件
err := emailSender.SendEmail(message)
if err != nil {
fmt.Println(err)
}
SendEmail 用于发送邮件
Click to show internal directories.
Click to hide internal directories.