dtnpzghys01643322
2018-06-01 20:39
浏览 77
已采纳

Golang SMTP发送空电子邮件

Why when I try to send email i'm received empty email?

    func contactHandler(w http.ResponseWriter, r *http.Request) {
        if r.Method == "GET" {
            t, _ := template.ParseFiles("template/static/contact.html")
            t.Execute(w, nil)
        } else if r.Method == "POST" {
            r.ParseForm()
            msg := "Name: " + r.Form["name"][0] + ", Email: " + r.Form["email"][0] + ", Message: " + r.Form["message"][0]
            println("out ", msg)
            smtp.SendMail("smtp.gmail.com:587", smtp.PlainAuth("", "login", "password", "smtp.gmail.com"), "sender@mail.com", []string{"me@mail.com"}, []byte(msg))
            http.Redirect(w, r, "/", 301)
        }
    }

But if I change []byte(msg) to []byte("TEST") I received email with TEST word

图片转代码服务由CSDN问答提供 功能建议

为什么当我尝试发送电子邮件时收到空电子邮件?</ p>

  func contactHandler(w http.ResponseWriter,r * http.Request){
如果r.Method ==“ GET” {
t,_:= template.ParseFiles(“ template / static / contact.html”  )
 t.Execute(w,nil)
}否则,如果r.Method ==“ POST” {
 r.ParseForm()
 msg:=“名称:” + r.Form [“ name”]  [0] +“,电子邮件:” + r.Form [“电子邮件”] [0] +“,消息:” + r.Form [“消息”] [0] 
 println(“ out”,msg)\  n smtp.SendMail(“ smtp.gmail.com:587”,smtp.PlainAuth(“”,“ login”,“ password”,“ smtp.gmail.com”),“ sender@mail.com”,[]字符串 {“ me@mail.com”},[] byte(msg))
 http.Redirect(w,r,“ /”,301)
} 
} 
 </ code> </ pre> \  n 
 

但是,如果我将 [] byte(msg)</ code>更改为 [] byte(“ TEST”)</ code>,则我收到了包含测试字词的电子邮件</ p> \ n </ div>

1条回答 默认 最新

相关推荐 更多相似问题