kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.66k stars 265 forks source link

Cannot make blank line in plaintext email #15

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hello,

Thanks for what's been a great tool so far. However, I'm running into an issue where I can't seem to be able to send an entirely blank line in a plaintext email (i.e. no HTML). My call looks something like this:

def send_email(self):
   self._yag.send(to = '<my email here>',
                  subject = '<subject here>',
                  contents = create_email_body())

where create_email_body() returns a list of strings, something like this:

def create_email_body():
    body = ['First line.', '\n', 'Second line.', 'Third line.']
    return [yagmail.yagmail.raw(s) for s in body]

And I would have wanted this to email as:

First line.

Second line.
Third line.

However, it always emails as:

First line.
Second line.
Third line.

I.e., I can't seem to be able to have a blank line in my plaintext email.

I have tried the above, and passing it as raw, passing it as a concatenated string, passing it as a raw'd concatenated string, having the newline character appear at the end/beginning of a value, other space characters like ' ' or '\t', etc., but no luck. It always requires at least one normal character, upon which just that string shows up in the line.

Any thoughts? I am currently using yagmail 0.4.110 on python 3.4.3.

kootenpv commented 9 years ago

Thanks for filing the issue. It seems to be a big one (not easily solvable). I'm very sorry!

I also tried a lot of things, and it seems that it does not work because raw is still being used as html.

Perhaps try:

['First line.', '<br>', 'Second line.', 'Third line.']

It shows weirdly for my gmail, but perhaps it could work for you?

I guess I'll maybe have to develop further where it is also possible to send real text-only messages.

This won't happen really soon though (not within days).

My apologies, Pascal

ghost commented 9 years ago

Thanks for the response, no worries! It does seem like a very strange error.

Well, I just tried that suggestion of the <br>, and it actually does seem to work! Could you say how it shows weirdly in your gmail?

But I think that's just because yeah, my email client is picking up the HTML version rather than the text version still. I will have to try with a text-only email client soon.

So just to make sure I understand, the problem is there doesn't seem to be a way to have it only send the text version, rather than both the text and HTML? Maybe I am misunderstanding the issue.

Again, no worries, and thanks already so far.

kootenpv commented 9 years ago

It for me shows like the last 2 sentences are folded (pretty much comparable to having to unfold old replices) in gmail.

The main issue is that it'll be sending a HTML email regardless. The raw method only means that it will not try to work magic on it (neither try to open it as a file, nor trying to use a parser to parse it as HTML).

It also always sets the "alternative" though, so I think/hope that it will be good for text-only clients, regardless that it is always sent as HTML.

Hope that clarifies a bit, and I hope yagmail will work for your purpose at this moment.

ghost commented 9 years ago

Ah okay I understand. Yes, I think it's good for now. Thanks again :+1:

kootenpv commented 9 years ago

As per a recent version, newlines are being replaced with <br>