1
votes

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.

1
See the tests for example uses of the multipart package.Bayta Darell

1 Answers

1
votes

You may like this package 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)
}