email

package
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

发邮件

采用 gomail 发送邮件,支持模板发送

使用

import (
  "gitee.com/novanest/toolkit/email"
)

func ExampleSample() {
	// 配置
	smtpEmail := &SmtpEmail{
		Host:               "smtp.qq.com",
		Port:               465,
		Username:           "123456@qq.com",
		Password:           "这是一个密码",
		InsecureSkipVerify: true,
		SignName:           "测试",
	}
	// 发送邮件
	err := smtpEmail.SendEmail(SmtpTemplate{
		MailFrom: "发件人",                                // 必填
		MailTo:   []string{"收件人"},                      // 必填
		BccTo:    []string{"密送人"},                      // 选填
		CCTo:     []string{"抄送人"},                      // 选填
		Subject:  "邮件主题",                               // 必填
		Body:     "邮件正文",                               // 必填
		Attach:   "附件",                                 // 选填
		Embed:    map[string]string{"图片位唯一标识": "图片路径"}, // 选填
	})
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Email

type Email struct {
	Sender  gomail.SendCloser
	Message *gomail.Message
}

type SmtpEmail

type SmtpEmail struct {
	// SMTP服务器的主机
	Host string
	// SMTP服务器的端口
	Port int64
	// SMTP服务器的用户名
	Username string
	// SMTP服务器的密码
	Password string
	// InsecureSkipVerify
	InsecureSkipVerify bool
	// 签名
	SignName string
}

func (*SmtpEmail) SendEmail

func (s *SmtpEmail) SendEmail(req SmtpTemplate) error

发送邮件 from: 发件人 mailTo: 收件人 ccTo: 抄送人 subject: 邮件主题 body: 邮件正文 (纯文本或 HTML) attach: 附件 Embed: 嵌入图片

type SmtpTemplate

type SmtpTemplate struct {
	// 发件人
	MailFrom string
	// 收件人
	MailTo []string
	// 密送
	BccTo []string
	// 抄送人
	CCTo []string
	// 邮件主题
	Subject string
	// 邮件正文
	Body string
	// 附件
	Attach string
	// 图片
	Embed map[string]string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL