golang邮箱登录验证(可以作为代替企业OA登录)

import (
	"crypto/tls"
	"fmt"
	"github.com/go-gomail/gomail"
)

func LoginByEmail(host string, port int, username string, passwd string) (bool,error) {
	dialer := gomail.NewDialer(host, port, username, passwd)
	//解决x509报错的问题。证书不通过。跳过证书验证
	config := &tls.Config{ServerName: host, InsecureSkipVerify: true}
	dialer.TLSConfig = config
	_,err := dialer.Dial()
	if err != nil {
		fmt.Println(err)
		fmt.Println("登录失败")
		return false, err
	}
	return true, nil
}

  

posted @ 2020-05-06 17:00  zipon  阅读(756)  评论(0编辑  收藏  举报