Maybe this?
html = pd.DataFrame([[1,2,3], ['dog', 'cat', 42]]).to_html()
part1 = MIMEText(html, 'html')
msg.attach(part1)
part2 = MIMEText('html')
coolstring = 'This is a dope-ass DataFrame yo'
part2.set_payload(coolstring)
msg.attach(part2)
though I think it's too similiar to to #2 below. Output follows:
>> print msg
# ...header with my email whoops...
--===============0888735609==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<table border="1" class="dataframe">
#...DataFrame html...
</table>
--===============0888735609==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
This is a dope-ass DataFrame yo
--===============0888735609==--
Found a couple of ways looking through the examples and by listing out the methods on MIMEMultipart through the equivalent of dir(MIMEMultipart)
Three guesses that you'll have to test:
1) You can set an epilogue by
msg.epilogue = 'This is a dope-ass DataFrame yo'
Not sure where or if this ends up on the email body however.
2) Create another MIMEText and attach it too. This seems to be how they accomplish sending loads of pictures at once in the examples, so this may be your best bet. Probably should have led with this.
part_text = MIMEText('This is some text, yessir')
msg.attach(part_text)
It kinda looks like it got there since the boundary divisions are the same.
>> print msg.as_string()
Content-Type: multipart/alternative; boundary="===============1672307235=="
MIME-Version: 1.0
Subject: Subject Text
From: EMAIL
To: EMAIL
--===============1672307235==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<table border="1" class="dataframe">
# ...DataFrame in HTML here...
</table>
--===============1672307235==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
This is some text, yessir
--===============1672307235==--
3) Since to actually send it in server.sendmail(sender, recipients, msg.as_string()) you convert msg to a string, your other option would be to manually add some HTML text into msg.as_string() directly. Something like
msg.as_string().replace('</table>', '</table>\n<p>...your text here</p>')
would be messy but should work.
Let me know if any of these are helpful! I'm kinda shooting in the dark because I can't test it right now. Good luck!