Closed pjebs closed 8 years ago
` message.SetBody("text/html", "Hello html pj")
message.AddAlternative("text/plain", "Hello pj")
` This produces:
`
--94a45f8d9e1210c11d7ca9a070acc3618c1f827c3c928506d7a6e5a4064d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello html pj --94a45f8d9e1210c11d7ca9a070acc3618c1f827c3c928506d7a6e5a4064d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello pj --94a45f8d9e1210c11d7ca9a070acc3618c1f827c3c928506d7a6e5a4064d-- `
Hotmail shows the html version. Gmail shows the text/plain version.
According to the official standard: http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
In general, user agents that compose multipart/alternative entities should place the body parts in increasing order of preference, that is, with the preferred format last.
Gmail respects the order (i.e. bottom is preferred). Your code should make the SetBody
string go to the bottom. The AddAlternative
string should go to the top.
Currently you have it the wrong way around.
I presume the reason why hotmail always shows the html version is due to a user setting or their default setting is always show html if available.
It is working as intended. The parts of the message are added in the order defined by the user. Reversing the order would be confusing.
What is so confusing? SetBody should set your preferred message. AddAlternative() should set your backup message if SetBody can't be used by the email client.
This means SetBody should be at the bottom. AddAlternative should be at the top. Simple!
What you have implemented is actually more confusing. My interpretation of what should happen is directly based on the method names. Your documentation does not even state that it is based on which order the developer adds it.
Either way, Excellent work!
In fact, when I swapped them around as you suggested:
message.AddAlternative("text/plain", "Hello pj") message.SetBody("text/html", "Hello html <b>pj</b>")
The AddAlternative does not even work! hence is not even added.
You should follow the example: https://godoc.org/gopkg.in/gomail.v2#example-Message-AddAlternative
I'll make the doc clearer.
@alexcesaro you saying that the "order" the items are added, affects behaviour ??
@pedromorgan That's what he is saying. I just tested it. Although I consider it wrong, the work around is super easy.
Just make sure m.AddAlternative is added last and it contains your PREFERRED email content.
Sounds "wrong" to me also, and a future annoying "gotcha"!
I added some details to the documentation. Is it clear enough now?
Also please note that an email can have more than two alternative parts. One plain text part followed by an HTML part is a common use case but it is not the only one.
umm, its a bug afaik.. sorry..
I am not sure I understand which bug you are talking about. Could you provide some details?
` message.SetBody("text/plain", "Hello pj")
` This produces:
`
--908b4cfdd408aaeb4ad5a5525eed978aa6361f8e322bf69397de36fa21d6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello pj --908b4cfdd408aaeb4ad5a5525eed978aa6361f8e322bf69397de36fa21d6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello html pj --908b4cfdd408aaeb4ad5a5525eed978aa6361f8e322bf69397de36fa21d6-- `
Hotmail shows the html version. Gmail shows the html version.