当前位置:网站首页>Golang sends email to the mail Library
Golang sends email to the mail Library
2022-07-27 04:05:00 【Crisp_ LF】
Golang Send mail Library email
- golang There is one in itself SMTP agreement , But the configuration of this protocol is more complex , So we use a third-party library to realize .
Humanized golang Email Library
email The packaging design is easy to use , Flexible enough . No restrictions . It is a very humanized golang Mail Library
email The library now supports the following
- Sender , The recipient , BCC and CC fields
- “[email protected]” and “[email protected]” Format email address
- The text and HTML Message body
- The attachment
- Reading receipt
Install and use
go get github.com/jordan-wright/email
- ️:email The version of this library >1 need Go1.5 Or later
- ️: If you need to work with previous Go Version is compatible with , have access to
gopkg.in/jordan-wright/email.v1The previous package in

Case study
Use QQ Send email
package main
import (
"github.com/jordan-wright/email"
"net/smtp"
)
func main() {
// Instantiation returns a structure
e := email.NewEmail()
//From: Who sent it
e.From = "Crisp <[email protected]>"
//To: To whom
e.To = []string{
"[email protected]"}
// CC , This place CC means , Who else can this email be copied to after it is sent
e.Bcc = []string{
"[email protected]"}
e.Cc = []string{
"[email protected]"}
// The theme , title
e.Subject = " test golang email library "
// General text content , Support html
e.Text = []byte(" Children !!!")
e.HTML = []byte("<h1>html Children !!!</h1>")
//send Method :smtp.qq.com:587:QQ email Relevant domain name port number smtp.PlainAuth: The first parameter is empty , The second parameter is your mailbox , The third parameter is authorization code , Here is how to get the authorization code
err := e.Send("smtp.qq.com:587", smtp.PlainAuth("", "[email protected]", " Authorization code ", "smtp.qq.com"))
if err != nil {
return
}
}
How to get the authentication password


Create structure directly create email
package main
import (
"github.com/jordan-wright/email"
"net/smtp"
"net/textproto"
)
func main() {
e := &email.Email{
To: []string{
"[email protected]"},
From: "Crisp <[email protected]>",
Subject: " test golang email library ",
Text: []byte(" Children !!!"),
HTML: []byte("<h1>html Children !!!</h1>"),
Headers: textproto.MIMEHeader{
},
}
//send Method :smtp.qq.com:587:QQ email Relevant domain name port number smtp.PlainAuth: to grant authorization The third parameter authorization code needs attention , It tells how to get the authorization code
err := e.Send("smtp.qq.com:587", smtp.PlainAuth("", "[email protected]", " Authorization code ", "smtp.qq.com"))
if err != nil {
return
}
}
Io.Reader Create email
o.Reader Any type that implements this interface creates an email email.NewEmailFromReader
Additional documents
e := NewEmail()
e.AttachFile("test.txt")
Use connection pooling to send large amounts of mail
(var ch <-chan *email.Email)
p := email.NewPool(
"smtp.gmail.com:587",
4,
smtp.PlainAuth("", "[email protected]", "ryqnogv3456dmaceiha", "smtp.qq.com"),
)
for i := 0; i < 4; i++ {
go func() {
for e := range ch {
err := p.Send(e, 10*time.Second)
if err != nil {
return
}
}
}()
}
边栏推荐
- Feitengtengrui d2000 won the "top ten hard core technologies" award of Digital China
- NFT digital collection system development: old brand literary magazines play with trendy Digital Collections
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- The fifth strong network cup national network security challenge Title reappearance (with title attachment, detailed explanation)
- Parallel desktop startup virtual machine "operation failed" problem solution
- Alibaba cloud server domain name and port web page cannot access the problem record
- 商业打假系列之第一百之--无聊的制度和管理流程真的可以扔进垃圾桶-顺便分析十几个无用的Unity游戏自检项目
- Chapter 4 决策树和随机森林
- VR全景人淘金“小心机”(上)
- A. YES or YES?
猜你喜欢
![Article main content extraction software [based on NLP technology]](/img/1c/7c1b0e9bc9af62308f4124104f6110.png)
Article main content extraction software [based on NLP technology]

NFT数字藏品系统开发:小蚁数智帮助品牌一键上链发行NFT

Development of NFT digital collection system: Xiaoyi digital intelligence helps brands launch NFT with one click on the chain

Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns

Process analysis of object creation

Programming implementation of eight queens

Director of meta quest content ecology talks about the original intention of APP lab design

Program to change the priority of the process in LabVIEW

Plato Farm有望通过Elephant Swap,进一步向外拓展生态

九方智投是正规公司吗?一起聊聊九方智投
随机推荐
mysql中case when返回多个字段处理方案
Application of one-dimensional array
暑假加餐|有钱人和你想的不一样(第5天)+电力系统潮流仿真(文档和Matlab代码)
LeetCode 第二十八天
分析一下CSDN大佬写的CAS,可重入锁, 非公平锁
第六周复习
函数指针与回调函数
C language introduction practice (12): find the value of natural constant e
Application, addition and deletion of B-tree
在Golang结构体中使用tag标签
Function pointer and callback function
ApacheCon Asia 预热直播之孵化器主题全回顾
It's confirmed that the registration of soft exam in the second half of 2022 will start in August
科目三: 济南章丘五号线
DataX无法连接对应的数据库(windows下可以,linux下失败)
Message queue learning -- Concepts
Golang发送邮件库email
Analyze CAS written by CSDN boss, re-entry lock, unfair lock
Do you really understand code rollback?
Kettle reads file split by line