ainsleyclark/go-mail

multipart email is not properly formatted when using smtp driver

kaptinlin opened this issue · 1 comments

Describe the bug
When send smtp email with both html and plain text, the Content-Type is not properly set.

To Reproduce

cfg := mail.Config{
	URL:         "smtp.gmail.com",
	FromAddress: "sender@example.com",
	FromName:    "Gopher",
	Password:    "my-password",
	Port:        587,
}

mailer, err := drivers.NewSMTP(cfg)
if err != nil {
	log.Fatalln(err)
}

tx := &mail.Transmission{
	Recipients: []string{"recipient@example.com"},
	Subject:    "Multipart Email Example",
	HTML:       "<h1>This is the HTML Section!</h1>",
	PlainText:  "Plain text email goes here!",
}

result, err := mailer.Send(tx)

Expected behavior

From: sender@example.com
To: recipient@example.com
Subject: Multipart Email Example
Content-Type: multipart/alternative; boundary="boundary-string"

--your-boundary
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Plain text email goes here!

--boundary-string
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<h1>This is the HTML Section!</h1>

--boundary-string--

There is a article for Multipart MIME Email Guide. And go-simple-email seems work well with it.

@kaptinlin can you confirm below?

MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8; boundary=be784b8c49238b246169a6a634ade1e42e1054dd03723c9f72bad8267a2e
Subject: Subject
To: hello@gmail.com

--be784b8c49238b246169a6a634ade1e42e1054dd03723c9f72bad8267a2e
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Hey!

--be784b8c49238b246169a6a634ade1e42e1054dd03723c9f72bad8267a2e
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<h1>Hey!</h1>

--be784b8c49238b246169a6a634ade1e42e1054dd03723c9f72bad8267a2e--

And for mutlipart:

MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=6564f3879c8a3d3757dcd42835c1bb64b994636889a5908e42f83dcd5239
Subject: Subject
To: hello@gmail.com

--6564f3879c8a3d3757dcd42835c1bb64b994636889a5908e42f83dcd5239
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Hey!

--6564f3879c8a3d3757dcd42835c1bb64b994636889a5908e42f83dcd5239
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<h1>Hey!</h1>

--6564f3879c8a3d3757dcd42835c1bb64b994636889a5908e42f83dcd5239