亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫(kù)/sql) database/sql/driver(數(shù)據(jù)庫(kù)/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯(cuò)誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語(yǔ)法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調(diào)色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達(dá)式) regexp/syntax runtime runtime(運(yùn)行時(shí)) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競(jìng)爭(zhēng)) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測(cè)試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時(shí)間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "net/smtp"

  • 概觀

  • 索引

  • 示例

概觀

smtp 包實(shí)現(xiàn)了RFC 5321中定義的簡(jiǎn)單郵件傳輸協(xié)議。它還實(shí)現(xiàn)了以下擴(kuò)展:

8BITMIME  RFC 1652AUTH      RFC 2554STARTTLS  RFC 3207

其他擴(kuò)展可能由客戶端處理。

smtp 軟件包被凍結(jié),不接受新的功能。一些外部軟件包提供更多功能??吹剑?/p>

https://godoc.org/?q=smtp

示例

編碼:

// Connect to the remote SMTP server.c, err := smtp.Dial("mail.example.com:25")if err != nil {
        log.Fatal(err)}// Set the sender and recipient firstif err := c.Mail("sender@example.org"); err != nil {
        log.Fatal(err)}if err := c.Rcpt("recipient@example.net"); err != nil {
        log.Fatal(err)}// Send the email body.wc, err := c.Data()if err != nil {
        log.Fatal(err)}_, err = fmt.Fprintf(wc, "This is the email body")if err != nil {
        log.Fatal(err)}err = wc.Close()if err != nil {
        log.Fatal(err)}// Send the QUIT command and close the connection.err = c.Quit()if err != nil {
        log.Fatal(err)}

索引

  • func SendMail(addr string, a Auth, from string, to []string, msg []byte) error

  • type Auth

  • func CRAMMD5Auth(username, secret string) Auth

  • func PlainAuth(identity, username, password, host string) Auth

  • type Client

  • func Dial(addr string) (*Client, error)

  • func NewClient(conn net.Conn, host string) (*Client, error)

  • func (c *Client) Auth(a Auth) error

  • func (c *Client) Close() error

  • func (c *Client) Data() (io.WriteCloser, error)

  • func (c *Client) Extension(ext string) (bool, string)

  • func (c *Client) Hello(localName string) error

  • func (c *Client) Mail(from string) error

  • func (c *Client) Quit() error

  • func (c *Client) Rcpt(to string) error

  • func (c *Client) Reset() error

  • func (c *Client) StartTLS(config *tls.Config) error

  • func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)

  • func (c *Client) Verify(addr string) error

  • type ServerInfo

示例

打包 PlainAuth SendMail

打包文件

auth.go smtp.go

func SendMail

func SendMail(addr string, a Auth, from string, to []string, msg []byte) error

SendMail 在 addr 連接到服務(wù)器,如果可能的話,切換到 TLS,如果可能,使用可選機(jī)制進(jìn)行身份驗(yàn)證,然后使用消息 msg 從地址發(fā)送到地址的電子郵件。addr 必須包含一個(gè)端口,如“mail.example.com:smtp”中所示。

to 參數(shù)中的地址是 SMTP RCPT 地址。

msg 參數(shù)應(yīng)該是一個(gè) RFC 822 風(fēng)格的電子郵件,首先包含標(biāo)題,空白行,然后是郵件正文。msg 的行應(yīng)該是 CRLF 終止的。 msg 標(biāo)題通常應(yīng)包含“From”,“To”,“Subject”和“Cc”等字段。發(fā)送“密件抄送”郵件是通過在 to 參數(shù)中包含一個(gè)電子郵件地址來完成的,但不包括在msg頭文件中。

SendMail 函數(shù)和 net / smtp 包是低級(jí)機(jī)制,不支持 DKIM 簽名,MIME 附件(請(qǐng)參閱mime / multipart包)或其他郵件功能。更高級(jí)別的軟件包存在于標(biāo)準(zhǔn)庫(kù)之外。

示例

package mainimport ("log""net/smtp")func main() {// Set up authentication information.
	auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com")// Connect to the server, authenticate, set the sender and recipient,// and send the email all in one step.
	to := []string{"recipient@example.net"}
	msg := []byte("To: recipient@example.net\r\n" +"Subject: discount Gophers!\r\n" +"\r\n" +"This is the email body.\r\n")
	err := smtp.SendMail("mail.example.com:25", auth, "sender@example.org", to, msg)if err != nil {
		log.Fatal(err)}}

type Auth

身份驗(yàn)證通過 SMTP 身份驗(yàn)證機(jī)制實(shí)施。

type Auth interface {        // Start begins an authentication with a server.        // It returns the name of the authentication protocol        // and optionally data to include in the initial AUTH message        // sent to the server. It can return proto == "" to indicate        // that the authentication should be skipped.        // If it returns a non-nil error, the SMTP client aborts        // the authentication attempt and closes the connection.        Start(server *ServerInfo) (proto string, toServer []byte, err error)        // Next continues the authentication. The server has just sent        // the fromServer data. If more is true, the server expects a        // response, which Next should return as toServer; otherwise        // Next should return toServer == nil.        // If Next returns a non-nil error, the SMTP client aborts        // the authentication attempt and closes the connection.        Next(fromServer []byte, more bool) (toServer []byte, err error)}

func CRAMMD5Auth

func CRAMMD5Auth(username, secret string) Auth

CRAMMD5Auth 返回一個(gè)Auth,它實(shí)現(xiàn) RFC 2195 中定義的 CRAM-MD5 認(rèn)證機(jī)制。返回的 Auth 使用給定的用戶名和密碼使用質(zhì)詢 - 響應(yīng)機(jī)制向服務(wù)器進(jìn)行認(rèn)證。

func PlainAuth

func PlainAuth(identity, username, password, host string) Auth

PlainAuth 返回一個(gè) Auth,它實(shí)現(xiàn) RFC 4616 中定義的 PLAIN 身份驗(yàn)證機(jī)制。返回的 Auth 使用給定的用戶名和密碼對(duì)主機(jī)進(jìn)行身份驗(yàn)證,并充當(dāng)身份。通常身份應(yīng)該是空字符串,充當(dāng)用戶名。

如果連接使用 TLS 或連接到本地主機(jī),PlainAuth 將僅發(fā)送憑據(jù)。否則,身份驗(yàn)證將失敗并出現(xiàn)錯(cuò)誤,而不會(huì)發(fā)送憑據(jù)。

示例

編碼:

// hostname is used by PlainAuth to validate the TLS certificate.hostname := "mail.example.com"auth := smtp.PlainAuth("", "user@example.com", "password", hostname)err := smtp.SendMail(hostname+":25", auth, from, recipients, msg)if err != nil {
        log.Fatal(err)}

type Client

客戶端代表到 SMTP 服務(wù)器的客戶端連接。

type Client struct {        // Text is the textproto.Conn used by the Client. It is exported to allow for        // clients to add extensions.
        Text *textproto.Conn        // contains filtered or unexported fields}

func Dial

func Dial(addr string) (*Client, error)

Dial 返回一個(gè)新的連接到 SMTP 服務(wù)器的客戶端。 addr 必須包含一個(gè)端口,如“mail.example.com:smtp”中所示。

func NewClient

func NewClient(conn net.Conn, host string) (*Client, error)

NewClient 使用現(xiàn)有連接和主機(jī)作為服務(wù)器名稱返回一個(gè)新的客戶端,以便在進(jìn)行身份驗(yàn)證時(shí)使用。

func (*Client) Auth

func (c *Client) Auth(a Auth) error

Auth 使用提供的認(rèn)證機(jī)制來認(rèn)證客戶端。認(rèn)證失敗將關(guān)閉連接。只有通告 AUTH 擴(kuò)展的服務(wù)器才支持此功能。

func (*Client) Close

func (c *Client) Close() error

Close 關(guān)閉連接。

func (*Client) Data

func (c *Client) Data() (io.WriteCloser, error)

數(shù)據(jù)向服務(wù)器發(fā)出 DATA 命令并返回可用于寫入郵件標(biāo)題和正文的編寫器。調(diào)用者應(yīng)該在調(diào)用c上的更多方法之前關(guān)閉作者。對(duì)數(shù)據(jù)的調(diào)用必須在一個(gè)或多個(gè)對(duì) Rcpt 的調(diào)用之前進(jìn)行。

func (*Client) Extension

func (c *Client) Extension(ext string) (bool, string)

Extension 報(bào)告擴(kuò)展是否受服務(wù)器支持。擴(kuò)展名不區(qū)分大小寫。如果支持?jǐn)U展,Extension 還會(huì)返回一個(gè)字符串,其中包含服務(wù)器為擴(kuò)展指定的任何參數(shù)。

func (*Client) Hello

func (c *Client) Hello(localName string) error

Hello 將 HELO 或 EHLO 作為給定的主機(jī)名稱發(fā)送到服務(wù)器。僅當(dāng)客戶端需要控制所使用的主機(jī)名稱時(shí)才需要調(diào)用此方法。否則客戶端會(huì)自動(dòng)將自身介紹為“本地主機(jī)”。如果調(diào)用 Hello,則必須在任何其他方法之前調(diào)用它。

func (*Client) Mail

func (c *Client) Mail(from string) error

郵件使用提供的電子郵件地址向服務(wù)器發(fā)出MAIL 命令。如果服務(wù)器支持 8BITMIME 擴(kuò)展,則 Mail 會(huì)添加 BODY = 8BITMIME 參數(shù)。這將啟動(dòng)一個(gè)郵件事務(wù),然后是一個(gè)或多個(gè) Rcpt 調(diào)用。

func (*Client) Quit

func (c *Client) Quit() error

退出發(fā)送 QUIT 命令并關(guān)閉連接到服務(wù)器。

func (*Client) Rcpt

func (c *Client) Rcpt(to string) error

Rcpt 使用提供的電子郵件地址向服務(wù)器發(fā)出 RCPT 命令。對(duì) Rcpt 的調(diào)用必須在對(duì) Mail 的調(diào)用之后進(jìn)行,然后可以進(jìn)行數(shù)據(jù)調(diào)用或其他 Rcpt 調(diào)用。

func (*Client) Reset

func (c *Client) Reset() error

重置將 RSET 命令發(fā)送到服務(wù)器,中止當(dāng)前的郵件事務(wù)。

func (*Client) StartTLS

func (c *Client) StartTLS(config *tls.Config) error

StartTLS 發(fā)送 STARTTLS 命令并加密所有進(jìn)一步的通信。只有通告 STARTTLS 擴(kuò)展的服務(wù)器才支持此功能。

func (*Client) TLSConnectionState

func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)

TLSConnectionState 返回客戶端的 TLS 連接狀態(tài)。如果 StartTLS 不成功,則返回值為零值。

func (*Client) Verify

func (c *Client) Verify(addr string) error

驗(yàn)證檢查服務(wù)器上電子郵件地址的有效性。如果驗(yàn)證返回 nil ,則地址有效。非零返回不一定表示無效地址。出于安全原因,許多服務(wù)器不會(huì)驗(yàn)證地址。

type ServerInfo

ServerInfo 記錄有關(guān) SMTP 服務(wù)器的信息。

type ServerInfo struct {
        Name string   // SMTP server name
        TLS  bool     // using TLS, with valid certificate for Name
        Auth []string // advertised authentication mechanisms}
Previous article: Next article: