multipart email in go


I’m trying to send multipart-emails using golang, but I can’t figure out how to create them. I know there’s a multipart package, but there are no example how to use it.

I already tried the library mailyak, but it doesn’t work like it should. So, how can I create multipart emails with normal golang smtp/multipart package?

The mail should have a html and a plain-text part.


You may like this package

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

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

// send it
auth := smtp.PlainAuth("", "", "pwd", "")
if err := email.Send("", auth, m); err != nil {

Answered By – Alex Pliutau

Answer Checked By – Candace Johnson (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.