GO語言"net/smtp"包中"PlainAuth"函數的用法及代碼示例。
用法:
func PlainAuth(identity, username, password, host string) Auth
PlainAuth 返回一個 Auth,它實現了 RFC 4616 中定義的 PLAIN 身份驗證機製。返回的 Auth 使用給定的用戶名和密碼來驗證主機並充當身份。通常身份應該是空字符串,作為用戶名。
PlainAuth 隻會在連接使用 TLS 或連接到 localhost 時發送憑據。否則身份驗證將失敗並出現錯誤,而不發送憑據。
例子:
package main
import (
"log"
"net/smtp"
)
// variables to make ExamplePlainAuth compile, without adding
// unnecessary noise there.
var (
from = "gopher@example.net"
msg = []byte("dummy message")
recipients = []string{"foo@example.com"}
)
func main() {
// 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)
}
}
相關用法
- GO PutUvarint用法及代碼示例
- GO ParseAddress用法及代碼示例
- GO Print用法及代碼示例
- GO ParseUint用法及代碼示例
- GO ParseIP用法及代碼示例
- GO Pow10用法及代碼示例
- GO Printf用法及代碼示例
- GO ParseMediaType用法及代碼示例
- GO ParseInt用法及代碼示例
- GO ParseCIDR用法及代碼示例
- GO PutVarint用法及代碼示例
- GO Perm用法及代碼示例
- GO Pipe用法及代碼示例
- GO ParseInLocation用法及代碼示例
- GO PathUnescape用法及代碼示例
- GO ParseDuration用法及代碼示例
- GO ParseFile用法及代碼示例
- GO Parse用法及代碼示例
- GO Pool用法及代碼示例
- GO Println用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 PlainAuth。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。