2017-12-02 146 views
0

我試圖發送使用golang的多部分電子郵件,但我無法弄清楚如何創建它們。我知道有一個多部分包,但沒有例子如何使用它。mutlipart電子郵件進去

我已經試過圖書館mailyak,但它不工作,它應該。那麼,我怎樣才能用普通的golang smtp/multipart包創建多部分電子郵件?

郵件應該有一個html和一個純文本部分。

+1

參見[試驗](https://golang.org/src/mime/multipart/writer_test.go)例如多部分包裝的用途。 –

回答

0

您可能喜歡這個包https://github.com/scorredoira/email

// compose the message 
m := email.NewMessage("Hi", "this is the body") 
m.From = mail.Address{Name: "From", Address: "[email protected]"} 
m.To = []string{"[email protected]"} 

// add attachments 
if err := m.Attach("email.go"); err != nil { 
    log.Fatal(err) 
} 

// send it 
auth := smtp.PlainAuth("", "[email protected]", "pwd", "smtp.zoho.com") 
if err := email.Send("smtp.zoho.com:587", auth, m); err != nil { 
    log.Fatal(err) 
}