目前大多应用都是手机登录,但是作为开源的一个软件,或者是私有的一个应用,那么使用手机短信接收验证码成本比较高,使用邮箱相对更容易,
这里从tinode中取出发邮件的部分做一个测试,
其中邮箱一般需要设置后才能使用SMTP方式发送邮件,设置方式参考:
邮件其实是有格式的,不是随便发一个字符串过去就好了
func randomBoundary() string {
var buf [24]byte
rand.Read(buf[:])
return fmt.Sprintf("tinode--%x", buf[:])
}
func GetMessage(SendFrom, to, title, dataType, content string) ([]byte, error) {
message := &bytes.Buffer{}
// Common headers.
fmt.Fprintf(message, "From: %s\r\n", SendFrom)
fmt.Fprintf(message, "To: %s\r\n", to)
message.WriteString("Subject: ")
// Old email clients may barf on UTF-8 strings.
// Encode as quoted printable with 75-char strings separated by spaces, split by spaces, reassemble.
message.WriteString(strings.Join(strings.Split(mime.QEncoding.Encode("utf-8", title), " "), "\r\n "))
message.WriteString("\r\n")