mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
Add support for HTML alternative message body
The code has been updated to allow for an HTML alternative to the plain text body in messages. This includes adding a new function to add this alternative body along with additional unit tests to ensure the multipart messages are properly constructed. The tests also check the correct usage of different charsets.
This commit is contained in:
parent
68088577ba
commit
2f60d9c5df
1 changed files with 21 additions and 0 deletions
|
@ -53,6 +53,7 @@ func TestMsgWriter_writeMsg(t *testing.T) {
|
|||
m.SetDateWithValue(now)
|
||||
m.SetMessageIDWithValue("message@id.com")
|
||||
m.SetBodyString(TypeTextPlain, "This is the body")
|
||||
m.AddAlternativeString(TypeTextHTML, "This is the alternative body")
|
||||
buf := bytes.Buffer{}
|
||||
mw := &msgWriter{w: &buf, c: CharsetUTF8, en: mime.QEncoding}
|
||||
mw.writeMsg(m)
|
||||
|
@ -95,6 +96,26 @@ func TestMsgWriter_writeMsg(t *testing.T) {
|
|||
if !strings.Contains(ms, "\r\n\r\nThis is the body") {
|
||||
ea = append(ea, "Message body")
|
||||
}
|
||||
|
||||
pl := m.GetParts()
|
||||
if len(pl) <= 0 {
|
||||
t.Errorf("expected multiple parts but got none")
|
||||
return
|
||||
}
|
||||
if len(pl) == 2 {
|
||||
ap := pl[1]
|
||||
ap.SetCharset(CharsetISO88591)
|
||||
}
|
||||
buf.Reset()
|
||||
mw.writeMsg(m)
|
||||
ms = buf.String()
|
||||
if !strings.Contains(ms, "\r\n\r\nThis is the alternative body") {
|
||||
ea = append(ea, "Message alternative body")
|
||||
}
|
||||
if !strings.Contains(ms, `Content-Type: text/html; charset=ISO-8859-1`) {
|
||||
ea = append(ea, "alternative body charset")
|
||||
}
|
||||
|
||||
if len(ea) > 0 {
|
||||
em := "writeMsg() failed. The following errors occurred:\n"
|
||||
for e := range ea {
|
||||
|
|
Loading…
Reference in a new issue