How to send an email using Go with an HTML formatted body?

Assuming that you’re using the net/smtp package and so the smtp.SendMail function, you just need to declare the MIME type in your message.

subject := "Subject: Test email from Go!\n"
mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
body := "<html><body><h1>Hello World!</h1></body></html>"
msg := []byte(subject + mime + body)

smtp.SendMail(server, auth, from, to, msg)

Hope this helps =)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)