使用StartTLS
2019-04-25 13:36:29
17092
我們知道smtp是郵件傳輸協(xié)議,傳輸過程中往往需要加密
直接使用TLS/SSL加密當(dāng)然簡單明白,但是為了兼容傳統(tǒng)的傳輸方式,出現(xiàn)了StartTLS
簡單說就是先使用明文通信,如果雙方支持加密的話升級為TLS加密通信
當(dāng)然,前提是郵箱服務(wù)器支持StartTLS(各服務(wù)商支持并不相同),目前來看,還是老老實實tls吧
放一下標準庫里的StartTLS實現(xiàn)
// StartTLS sends the STARTTLS command and encrypts all further communication.
// Only servers that advertise the STARTTLS extension support this function.
func (c Client) StartTLS(config tls.Config) error {
if err := c.hello(); err != nil {
return err
} , , err := c.cmd(220, "STARTTLS")
if err != nil {
return err
}
c.conn = tls.Client(c.conn, config)
c.Text = textproto.NewConn(c.conn)
c.tls = true
return c.ehlo()
}如果服務(wù)端僅支持TLS,c.hello()會無法收到正確信息,c.cmd()報錯