go-gomail / gomail

The best way to send emails in Go.
MIT License
4.3k stars 570 forks source link

How to send the whole html page with the text/html contentType. #122

Open shuangyangqian opened 5 years ago

shuangyangqian commented 5 years ago

Hi, everyone: when i use gmail to send a email, i choose the text/html contentType. And the body string i edit a whole html string. But i only receive the body that i send with the gomail.

the code is: ` package main

import ( "github.com/go-gomail/gomail" "crypto/tls" )

func main() { m := gomail.NewMessage() m.SetAddressHeader("From", "xxx@xx.com", "test") m.SetHeader("To", "xxx@xxx.com") htmlBody := `

this is a title
             <body><h1>Hello world</h1></body>`
m.SetBody("text/html", htmlBody)
d := gomail.NewDialer("xxx.xxx.com", 123, "xxx@xx.com", "xxx")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
d.DialAndSend(m)

} `

the email which i received is only the

Hello world

. why the title--this is a title in the html head is ignored.

davleb commented 5 years ago

It is very normal for me, not a bug. Web client is not a web browser. In the context of a mail, the subject is the title, you set it as any other header: m.SetHeader("Subject", "Newsletter from your prefered online shop"). m.SetBody only takes ... the body part of your html ! Not strange. Another limitation is that you cannot probably "css style" the content of the body since it is done using the HEAD balise, not the BODY. This is more problematic for me.

pedromorgan commented 5 years ago

see #104 and #108