CZ-NIC / envelope

Insert a message and attachments and send e-mail / sign / encrypt contents by a single line.
Other
171 stars 12 forks source link

line breaks get dropped #4

Closed aaronkaplan closed 4 years ago

aaronkaplan commented 4 years ago

I am trying to send a mail this way:

body = """
  Some very long mail
  With line breaks
     and formatting
        and TABs etc.
  best regards,
   your robot
"""

and then send it like this:

envelope.envelope()\
        .message(body)\
        .subject(subject)\
        .to(email)\
        .sender(smtp_from)\
        .smtp("localhost")\
        .send()

But the long body with line breaks gets put into one single line. How to fix this?

e3rd commented 4 years ago

Sorry Aaron, I missed that issue. By default, we are sending HTML mail.

So a quick fix will be to do body = "\n<br>".join(body.split("\n")) . I am planning to add the possibility to send the e-mail in text/plain format too without doubt. But I'm stuck at this decision. There are four possibilities to send the e-mail:

  1. text/html (current default)
  2. text/plain
  3. autodetect if <br> or <p is in the text → text/html, else text/plain
  4. same as 3. + when text/html is used, add text/plain as an alternative

What should be the default behaviour in the next release, 3. or 4.? I'd vote for 3. because that's the way I would expect envelope to work as a developer. ... But there are articles on the net saying it's a good thing to always present a text alternative for your html text.

e3rd commented 4 years ago

I've implemented 3. for the while.

Try adding .mime("plain") to your envelope object to preserve all the formatting. For the instant, I left "html" as the default and only line breaks are converted automatically <br> if forgotten.

aaronkaplan commented 4 years ago

Hi!

I think it makes sense to give the user an option. Similar to most mail clients, they also allow the user to select which format should be used by default. I recommend to set text/plain as the default format.

Best, a.

On 15.01.2020, at 18:23, Edvard Rejthar notifications@github.com wrote:

Sorry Aaron, I missed that issue. By default, we are sending HTML mail.

So a quick fix will be to do body = "\n
".join(body.split("\n")) . I am planning to add the possibility to send the e-mail in text/plain format too without doubt. But I'm stuck at this decision. There are four possibilities to send the e-mail:

• text/html (current default) • text/plain • autodetect if
or <p is in the text → text/html, else text/plain • same as 3. + when text/html is used, add text/plain as an alternative What should be the default behaviour in the next release, 3. or 4.? I'd vote for 3. because that's the way I would expect envelope to work as a developer. ... But there are articles on the net saying it's a good thing to always present a text alternative for your html text.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

e3rd commented 4 years ago

You are right. User that writes down plaintext would expect text/plain. Now, user has the control over the mime with the mime function + by default .mime("auto") there is a detection whether the message is in HTML. If so, the message has "text/html" but if not, message keeps text/plain.