kootenpv / yagmail

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

send yagmail with html content, and receive mail get some blank line #124

Closed shenghaomail closed 5 years ago

shenghaomail commented 6 years ago

here is my script to send mail html = """\ <table width="500" border="2" bordercolor="red" cellspacing="2"> <tr> <td><strong>action</strong></td> <td><strong>total</strong></td> <td><strong>action</strong></td> <td><strong>pre</strong></td> <td><strong>unsure</strong></td> </tr> <tr> <td>node</a></td> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> </tr> </table> """ to = 'abc@abc.com' subject = 'This is obviously the subject' body = 'This is obviously the body' yag = SMTP_SSL(user = yag_user, password = yag_password, host = yag_host,port = yag_port) yag.send(to=to, subject=subject, contents=[body, html])

and there is some blank line between body and html

kootenpv commented 6 years ago

There's a separation of content between each element in contents.

If you want you could just do , contents=body + html, that should avoid the blank line?

shenghaomail commented 6 years ago

thank you for reply! Test the following three commands, and the execution results contain blank lines. yag.send(to=to, subject=subject, contents=[body, html]) yag.send(to=to, subject=subject, contents=body + html) yag.send(to=to, subject=subject, contents=html)

qq20180908-091612 2x
kootenpv commented 6 years ago

Newlines are converted to
as a matter of convenience.

You can avoid this using html = html.replace("\n", "")

shenghaomail commented 6 years ago

Thank you! blank lines is gone

kootenpv commented 5 years ago

Note that there is also a possibility now to add yag.send(contents="test\ntest", newline_to_break=False), that could also help.