Python Email in HTML format mimelib

后端 未结 2 1992
深忆病人
深忆病人 2021-01-16 12:03

I am trying to send two dataframes created in Pandas Python as a html format in an email sent from the python script.

I want to write a text and the table and repeat

相关标签:
2条回答
  • 2021-01-16 12:48

    The problem is that you are marking up the parts as multipart/alternative -- this means, "I have the information in multiple renderings; choose the one you prefer" and your email client is apparently set up to choose the HTML version. Both parts are in fact there, but you have tagged them as either/or where apparently you want both.

    The conventional quick fix would be to switch to multipart/related but really, what is the purpose of a text part which simply says the content is elsewhere?

    If you want the HTML as an attachment, maybe also set Content-Disposition: attachment (and supply a file name) for the HTML part.

    0 讨论(0)
  • 2021-01-16 13:03

    Use yagmail (full disclose: I'm the maintainer/developer):

    import time
    import yagmail
    yag = yagmail.SMTP(username, password)
    
    text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttps://www.python.org"
    html = df[['SYMBOL','ARBITRAGE BASIS %']].to_html()
    
    yag.send('albalb@gmail.com', "This a reminder call " + time.strftime("%c"), [text,html])
    

    yagmail exists to make it really easy for us to send emails using attachments, images, and html among other things.

    Get started by installing it using

    pip install yagmail
    
    0 讨论(0)
提交回复
热议问题