email

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 4 Imported by: 0

README

email

gomail基础上封装的go语言发邮件库


安装

go get -u gitee.com/yzsunjianguo/common_pkg/email


使用示例

    // 初始化,参数是为发送者邮箱和密码(不是登录密码)
    client, err := email.Init("xxxxxx@qq.com", "xxxxxx")

    // 发送邮件
	msg := &email.Message{
		To:          []string{"xxxxxx@qq.com"},
		Cc:          nil,
		Subject:     "title-demo",
		ContentType: "text/plain",
		Content:     "邮件内容demo-01",
		Attach:      "",
	}
	err := client.SendMessage(msg)

qq邮箱设置
开启邮箱服务
  • 登录qq邮箱(手机号已认证)。
  • 点击设置 --> 账户,找到STMP服务,点击开启,根据提示内容使用手机发短信到指定手机号码,开启完成后得到授权码,有了授权码就可以使用客户端收发邮件,获取授权码教程

邮箱的服务器地址和端口(使用SSL):

  • 发送邮件服务器:smtp.qq.com,端口号465或587

网易邮箱设置
开启邮箱服务
  • 登录126邮箱(手机号已认证)。
  • 点击设置 --> POP3/SMTP/IMAP,点击开启,根据提示内容使用手机发短信到指定手机号码,开启完成后得到授权码,有了授权码就可以使用客户端收发邮件,获取授权码教程

邮箱的服务器地址和端口(使用SSL):

  • 126邮箱:
    • 发送邮件服务器:smtp.126.com,端口号465或994
  • 163邮箱:
    • 发送邮件服务器:smtp.163.com,端口号465或994

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host     string // host smtp地址
	Port     int    // port 端口
	Username string // username 账户
	Password string // password 密码
}

Client 发送客户端

func Init

func Init(username string, password string) (*Client, error)

Init 实例化

func (*Client) SendMessage

func (c *Client) SendMessage(msg *Message) error

SendMessage 发送邮件

type Message

type Message struct {
	To          []string // 收件人
	Cc          []string // 抄送人
	Subject     string   // 标题
	ContentType string   // 内容的类型text/plain,text/html
	Content     string   // 发送内容
	Attach      string   // 附件
}

Message 内容

Jump to

Keyboard shortcuts

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