yagmail
yagmail copied to clipboard
How to send html file as attachment?
First of all thank you for the great app.
I have to send .html reports automatically. Idea is to send it as either attachment or inline. I tried several things:
yag=yagmail.SMTP('[email protected]','PASS')
contents = ["//path/to/file.html"]
yag.send('[email protected]', f'Subject',contents)
and
yag.send('[email protected]', f'Subject',yagmail.inline("//path/to/file.html"))
and
yag.send('[email protected]', f'Subject',yagmail.raw("//path/to/file.html"))
If I sent it as html attachment or inline, this is the result where I cannot see the html content.

If I change ".html" file name, to e.g. ".tt", the file is successfully attached. So, how can I attache a .html file without renaming it?
If you want to send it as inline, just write the HTML code directly in contents.
contents = "<h1>This is a big title!</h1>"
If you want to attach HTML files inline, write a function to extract the code from it and pass it to contents as a string.