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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。