Reputation: 79
I am using email Golang to send email and I am unable to send HTML content and attach more than one file and content. How to add more attached files and more than one table shown in the body email? I got the result by database.
m.Attach(cf.Attach) //attachment
Upvotes: 0
Views: 1077
Reputation: 1072
Save the .xlxs
file over the disk then attach it using path
. It will work perfectly.
Here is a sample code and it's working fine :
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "[email protected]")
m.SetHeader("To", "[email protected]")
m.SetAddressHeader("Cc", "[email protected]", "Vande")
m.SetHeader("Subject", "Hello! New Mail")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
m.Attach("attach.xlsx")
d := gomail.NewDialer("smtp.gmail.com", 2525, "user", "password")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
if err := d.DialAndSend(m); err != nil {
fmt.Print(err)
panic(err)
} else {
fmt.Print("sent")
}
}
Project Architecture :
send_mail //project name
attach.xlxs //file
main.go
go.mod
Upvotes: 1