使用golang发送邮件
参考
本文参考了github代码smtp ssl example及官方doc smtp示例
介绍
编写了一个struck支持ssl和非ssl发送邮件。本文使用了plain/text类型邮件
code
package email
import (
"crypto/tls"
"fmt"
"net"
"net/smtp"
"strings"
)
//Client simple email client support ssl
type Client struct {
user string
addr string
nickName string
isSSL bool
auth smtp.Auth
}
//New new email client
func New(user, password, nickName, host string, port int, isSsl bool) *Client {
ec := &Client{
user: user,
addr: fmt.Sprintf("%s:%d", host, port),
isSSL: isSsl,
auth: smtp.PlainAuth("", user, password, host),
}