Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart email is not properly formatted when using smtp driver #21

Open
kaptinlin opened this issue Aug 8, 2022 · 1 comment
Open

Comments

@kaptinlin
Copy link

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.

@ainsleyclark
Copy link
Owner

ainsleyclark commented Sep 20, 2022

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants